From be5d08647eb4f388210c0c03811cb4d7f0f487e7 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 5 Nov 2013 23:44:20 +0900 Subject: [PATCH] nghttpd: Add -c, --header-table-size option --- src/HttpServer.cc | 10 ++++++++-- src/HttpServer.h | 1 + src/nghttpd.cc | 13 ++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 1b82d8e5..6f636c47 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -73,7 +73,8 @@ Config::Config() verify_client(false), no_tls(false), no_flow_control(false), - output_upper_thres(1024*1024) + output_upper_thres(1024*1024), + header_table_size(-1) {} Request::Request(int32_t stream_id) @@ -362,7 +363,7 @@ int Http2Handler::on_connect() if(r != 0) { return r; } - nghttp2_settings_entry entry[2]; + nghttp2_settings_entry entry[3]; size_t niv = 1; entry[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; entry[0].value = 100; @@ -371,6 +372,11 @@ int Http2Handler::on_connect() entry[niv].value = 1; ++niv; } + if(config.header_table_size >= 0) { + entry[niv].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE; + entry[niv].value = config.header_table_size; + ++niv; + } r = nghttp2_submit_settings(session_, NGHTTP2_FLAG_NONE, entry, niv); if(r != 0) { return r; diff --git a/src/HttpServer.h b/src/HttpServer.h index bd4645db..458bcfd3 100644 --- a/src/HttpServer.h +++ b/src/HttpServer.h @@ -60,6 +60,7 @@ struct Config { bool no_tls; bool no_flow_control; size_t output_upper_thres; + ssize_t header_table_size; Config(); }; diff --git a/src/nghttpd.cc b/src/nghttpd.cc index 4f17f343..86b3cd9f 100644 --- a/src/nghttpd.cc +++ b/src/nghttpd.cc @@ -76,6 +76,8 @@ void print_help(std::ostream& out) << " -f, --no-flow-control\n" << " Disables connection and stream level flow\n" << " controls.\n" + << " -c, --header-table-size=\n" + << " Specify decoder header table size.\n" << " --color Force colored log output.\n" << " -h, --help Print this help.\n" << std::endl; @@ -95,12 +97,14 @@ int main(int argc, char **argv) {"verbose", no_argument, nullptr, 'v'}, {"verify-client", no_argument, nullptr, 'V'}, {"no-flow-control", no_argument, nullptr, 'f'}, + {"header-table-size", required_argument, nullptr, 'c'}, {"no-tls", no_argument, &flag, 1}, {"color", no_argument, &flag, 2}, {nullptr, 0, nullptr, 0} }; int option_index = 0; - int c = getopt_long(argc, argv, "DVd:fhv", long_options, &option_index); + int c = getopt_long(argc, argv, "DVc:d:fhv", long_options, &option_index); + char *end; if(c == -1) { break; } @@ -123,6 +127,13 @@ int main(int argc, char **argv) case 'v': config.verbose = true; break; + case 'c': + config.header_table_size = strtol(optarg, &end, 10); + if(errno == ERANGE || *end != '\0') { + std::cerr << "-c: Bad option value: " << optarg << std::endl; + exit(EXIT_FAILURE); + } + break; case '?': exit(EXIT_FAILURE); case 0: