nghttpd: Add --early-response option

This option is testing the client behavior when it gets response
before sending all request.
This commit is contained in:
Tatsuhiro Tsujikawa 2014-07-03 22:44:27 +09:00
parent 4b6f124b7e
commit 545732fed8
3 changed files with 30 additions and 9 deletions

View File

@ -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);
}

View File

@ -76,6 +76,7 @@ struct Config {
bool verify_client;
bool no_tls;
bool error_gzip;
bool early_response;
Config();
};

View File

@ -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: