nghttpd: Add --no-content-length option to omit content-length in response
This commit is contained in:
parent
027256d0b1
commit
b64fc3ac49
|
@ -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() {}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -76,6 +76,7 @@ struct Config {
|
|||
bool early_response;
|
||||
bool hexdump;
|
||||
bool echo_upload;
|
||||
bool no_content_length;
|
||||
Config();
|
||||
~Config();
|
||||
};
|
||||
|
|
|
@ -164,6 +164,8 @@ Options:
|
|||
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.
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue