Skip to content

Commit

Permalink
nghttpd: Add --no-content-length option to omit content-length in res…
Browse files Browse the repository at this point in the history
…ponse
  • Loading branch information
tatsuhiro-t committed Jan 7, 2016
1 parent 027256d commit b64fc3a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/HttpServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Config::Config()
max_concurrent_streams(100), header_table_size(-1), port(0),
verbose(false), daemon(false), verify_client(false), no_tls(false),
error_gzip(false), early_response(false), hexdump(false),
echo_upload(false) {}
echo_upload(false), no_content_length(false) {}

Config::~Config() {}

Expand Down Expand Up @@ -873,12 +873,14 @@ int Http2Handler::submit_file_response(const std::string &status,
std::string last_modified_str;
auto nva = make_array(http2::make_nv_ls(":status", status),
http2::make_nv_ll("server", NGHTTPD_SERVER),
http2::make_nv_ls("content-length", content_length),
http2::make_nv_ll("cache-control", "max-age=3600"),
http2::make_nv_ls("date", sessions_->get_cached_date()),
http2::make_nv_ll("", ""), http2::make_nv_ll("", ""),
http2::make_nv_ll("", ""));
size_t nvlen = 5;
http2::make_nv_ll("", ""), http2::make_nv_ll("", ""));
size_t nvlen = 4;
if (!get_config()->no_content_length) {
nva[nvlen++] = http2::make_nv_ls("content-length", content_length);
}
if (last_modified != 0) {
last_modified_str = util::http_date(last_modified);
nva[nvlen++] = http2::make_nv_ls("last-modified", last_modified_str);
Expand Down Expand Up @@ -1088,7 +1090,9 @@ void prepare_echo_response(Stream *stream, Http2Handler *hd) {

Headers headers;
headers.emplace_back("nghttpd-response", "echo");
headers.emplace_back("content-length", util::utos(length));
if (!hd->get_config()->no_content_length) {
headers.emplace_back("content-length", util::utos(length));
}

hd->submit_response("200", stream->stream_id, headers, &data_prd);
}
Expand Down
1 change: 1 addition & 0 deletions src/HttpServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ struct Config {
bool early_response;
bool hexdump;
bool echo_upload;
bool no_content_length;
Config();
~Config();
};
Expand Down
7 changes: 7 additions & 0 deletions src/nghttpd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ void print_help(std::ostream &out) {
Path to file that contains MIME media types and the
extensions that represent them.
Default: )" << config.mime_types_file << R"(
--no-content-length
Don't send content-length header field.
--version Display version information and exit.
-h, --help Display this help and exit.
Expand Down Expand Up @@ -209,6 +211,7 @@ int main(int argc, char **argv) {
{"hexdump", no_argument, &flag, 7},
{"echo-upload", no_argument, &flag, 8},
{"mime-types-file", required_argument, &flag, 9},
{"no-content-length", no_argument, &flag, 10},
{nullptr, 0, nullptr, 0}};
int option_index = 0;
int c = getopt_long(argc, argv, "DVb:c:d:ehm:n:p:va:", long_options,
Expand Down Expand Up @@ -340,6 +343,10 @@ int main(int argc, char **argv) {
mime_types_file_set_manually = true;
config.mime_types_file = optarg;
break;
case 10:
// no-content-length option
config.no_content_length = true;
break;
}
break;
default:
Expand Down

0 comments on commit b64fc3a

Please sign in to comment.