diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 344fcfd0..209933f5 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -66,7 +66,7 @@ const std::string NGHTTPD_SERVER = "nghttpd nghttp2/" NGHTTP2_VERSION; Config::Config() : data_ptr(nullptr), output_upper_thres(1024*1024), - padding_boundary(0), + padding(0), header_table_size(-1), port(0), verbose(false), @@ -931,14 +931,7 @@ ssize_t select_padding_callback void *user_data) { auto hd = static_cast(user_data); - auto bd = hd->get_config()->padding_boundary; - if(bd == 0) { - return frame->hd.length; - } - if(frame->hd.length == 0) { - return std::min(max_payload, bd); - } - return std::min(max_payload, (frame->hd.length + bd - 1) / bd * bd); + return std::min(max_payload, frame->hd.length + hd->get_config()->padding); } } // namespace @@ -988,7 +981,7 @@ void fill_callback(nghttp2_session_callbacks& callbacks, const Config *config) callbacks.on_data_chunk_recv_callback = on_data_chunk_recv_callback; callbacks.on_header_callback = on_header_callback; callbacks.on_begin_headers_callback = on_begin_headers_callback; - if(config->padding_boundary) { + if(config->padding) { callbacks.select_padding_callback = select_padding_callback; } } diff --git a/src/HttpServer.h b/src/HttpServer.h index 308d3b10..f89a1ee2 100644 --- a/src/HttpServer.h +++ b/src/HttpServer.h @@ -56,7 +56,7 @@ struct Config { std::string cert_file; void *data_ptr; size_t output_upper_thres; - size_t padding_boundary; + size_t padding; ssize_t header_table_size; uint16_t port; bool verbose; diff --git a/src/nghttp.cc b/src/nghttp.cc index 573b3672..59ca75d5 100644 --- a/src/nghttp.cc +++ b/src/nghttp.cc @@ -82,7 +82,7 @@ struct Config { std::string keyfile; std::string datafile; size_t output_upper_thres; - size_t padding_boundary; + size_t padding; ssize_t peer_max_concurrent_streams; ssize_t header_table_size; int32_t pri; @@ -100,7 +100,7 @@ struct Config { bool continuation; Config() : output_upper_thres(1024*1024), - padding_boundary(0), + padding(0), peer_max_concurrent_streams(NGHTTP2_INITIAL_MAX_CONCURRENT_STREAMS), header_table_size(-1), pri(NGHTTP2_PRI_DEFAULT), @@ -1131,14 +1131,7 @@ ssize_t select_padding_callback (nghttp2_session *session, const nghttp2_frame *frame, size_t max_payload, void *user_data) { - auto bd = config.padding_boundary; - if(bd == 0) { - return frame->hd.length; - } - if(frame->hd.length == 0) { - return std::min(max_payload, bd); - } - return std::min(max_payload, (frame->hd.length + bd - 1) / bd * bd); + return std::min(max_payload, frame->hd.length + config.padding); } } // namespace @@ -1598,7 +1591,7 @@ int run(char **uris, int n) } callbacks.on_data_chunk_recv_callback = on_data_chunk_recv_callback; callbacks.on_header_callback = on_header_callback; - if(config.padding_boundary) { + if(config.padding) { callbacks.select_padding_callback = select_padding_callback; } @@ -1723,9 +1716,8 @@ void print_help(std::ostream& out) << " is large enough as it is seen as unlimited.\n" << " -c, --header-table-size=\n" << " Specify decoder header table size.\n" - << " -b, --padding=\n" - << " Padding boundary for frame payload. Specify\n" - << " 0 to disable padding.\n" + << " -b, --padding= Add at most bytes to a frame payload as\n" + << " padding. Specify 0 to disable padding.\n" << " --color Force colored log output.\n" << " --continuation Send large header to test CONTINUATION.\n" << std::endl; @@ -1780,7 +1772,7 @@ int main(int argc, char **argv) print_help(std::cout); exit(EXIT_SUCCESS); case 'b': - config.padding_boundary = strtol(optarg, nullptr, 10); + config.padding = strtol(optarg, nullptr, 10); break; case 'n': config.null_out = true; diff --git a/src/nghttpd.cc b/src/nghttpd.cc index 30bbeb0e..9bb9d2c2 100644 --- a/src/nghttpd.cc +++ b/src/nghttpd.cc @@ -115,9 +115,8 @@ void print_help(std::ostream& out) << " -p/=/foo.png -p/doc=/bar.css\n" << " PATH and PUSH_PATHs are relative to document\n" << " root. See --htdocs option.\n" - << " -b, --padding=\n" - << " Padding boundary for frame payload. Specify\n" - << " 0 to disable padding.\n" + << " -b, --padding= Add at most bytes to a frame payload as\n" + << " padding. Specify 0 to disable padding.\n" << " -h, --help Print this help.\n" << std::endl; } @@ -156,7 +155,7 @@ int main(int argc, char **argv) config.verify_client = true; break; case 'b': - config.padding_boundary = strtol(optarg, nullptr, 10); + config.padding = strtol(optarg, nullptr, 10); break; case 'd': config.htdocs = optarg; diff --git a/src/shrpx.cc b/src/shrpx.cc index 48242dc1..ed551aff 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -676,8 +676,8 @@ void print_help(std::ostream& out) << " --backend-no-tls Disable SSL/TLS on backend connections.\n" << " --http2-no-cookie-crumbling\n" << " Don't crumble cookie header field.\n" - << " --padding=\n" - << " Padding boundary for HTTP/2 frame payload.\n" + << " --padding= Add at most bytes to a HTTP/2 frame payload\n" + << " as padding.\n" << " Specify 0 to disable padding. This option is\n" << " meant for debugging purpose and not intended\n" << " to enhance protocol security.\n" diff --git a/src/shrpx_http.cc b/src/shrpx_http.cc index 0c1db266..5788d09c 100644 --- a/src/shrpx_http.cc +++ b/src/shrpx_http.cc @@ -98,11 +98,7 @@ ssize_t select_padding_callback (nghttp2_session *session, const nghttp2_frame *frame, size_t max_payload, void *user_data) { - auto bd = get_config()->padding; - if(frame->hd.length == 0) { - return std::min(max_payload, bd); - } - return std::min(max_payload, (frame->hd.length + bd - 1) / bd * bd); + return std::min(max_payload, frame->hd.length + get_config()->padding); } } // namespace http