From 545732fed8e340db7bdddaade35aa31614264fbb Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 3 Jul 2014 22:44:27 +0900 Subject: [PATCH] nghttpd: Add --early-response option This option is testing the client behavior when it gets response before sending all request. --- src/HttpServer.cc | 30 +++++++++++++++++++++--------- src/HttpServer.h | 1 + src/nghttpd.cc | 8 ++++++++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 9f660cd8..c80529c4 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -113,7 +113,8 @@ Config::Config() daemon(false), verify_client(false), no_tls(false), - error_gzip(false) + error_gzip(false), + early_response(false) {} Stream::Stream(Http2Handler *handler, int32_t stream_id) @@ -961,16 +962,21 @@ ssize_t file_read_callback while((nread = read(fd, buf, length)) == -1 && errno == EINTR); if(nread == -1) { - if(stream) { - remove_stream_read_timeout(stream); - remove_stream_write_timeout(stream); - } + remove_stream_read_timeout(stream); + remove_stream_write_timeout(stream); return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; } if(nread == 0) { *data_flags |= NGHTTP2_DATA_FLAG_EOF; + + if(nghttp2_session_get_stream_remote_close(session, stream_id) == 0) { + remove_stream_read_timeout(stream); + remove_stream_write_timeout(stream); + + hd->submit_rst_stream(stream, NGHTTP2_NO_ERROR); + } } return nread; @@ -1215,8 +1221,9 @@ int hd_on_frame_recv_callback if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) { remove_stream_read_timeout(stream); - - prepare_response(stream, hd); + if(!hd->get_config()->early_response) { + prepare_response(stream, hd); + } } else { add_stream_read_timeout(stream); } @@ -1250,12 +1257,17 @@ int hd_on_frame_recv_callback hd->submit_rst_stream(stream, NGHTTP2_PROTOCOL_ERROR); return 0; } + + if(hd->get_config()->early_response) { + prepare_response(stream, hd); + } } if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) { remove_stream_read_timeout(stream); - - prepare_response(stream, hd); + if(!hd->get_config()->early_response) { + prepare_response(stream, hd); + } } else { add_stream_read_timeout(stream); } diff --git a/src/HttpServer.h b/src/HttpServer.h index 91cba297..1d3fa456 100644 --- a/src/HttpServer.h +++ b/src/HttpServer.h @@ -76,6 +76,7 @@ struct Config { bool verify_client; bool no_tls; bool error_gzip; + bool early_response; Config(); }; diff --git a/src/nghttpd.cc b/src/nghttpd.cc index 1a29d3c0..fc3adc7c 100644 --- a/src/nghttpd.cc +++ b/src/nghttpd.cc @@ -137,6 +137,9 @@ Options: Path to file that contains DH parameters in PEM format. Without this option, DHE cipher suites are not available. + --early-response Start sending response when request HEADERS is + received, rather than complete request is + received. --version Display version information and exit. -h, --help Display this help and exit.)" << std::endl; @@ -164,6 +167,7 @@ int main(int argc, char **argv) {"color", no_argument, &flag, 2}, {"version", no_argument, &flag, 3}, {"dh-param-file", required_argument, &flag, 4}, + {"early-response", no_argument, &flag, 5}, {nullptr, 0, nullptr, 0} }; int option_index = 0; @@ -242,6 +246,10 @@ int main(int argc, char **argv) // dh-param-file config.dh_param_file = optarg; break; + case 5: + // early-response + config.early_response = true; + break; } break; default: