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:
parent
4b6f124b7e
commit
545732fed8
|
@ -113,7 +113,8 @@ Config::Config()
|
||||||
daemon(false),
|
daemon(false),
|
||||||
verify_client(false),
|
verify_client(false),
|
||||||
no_tls(false),
|
no_tls(false),
|
||||||
error_gzip(false)
|
error_gzip(false),
|
||||||
|
early_response(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Stream::Stream(Http2Handler *handler, int32_t stream_id)
|
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);
|
while((nread = read(fd, buf, length)) == -1 && errno == EINTR);
|
||||||
|
|
||||||
if(nread == -1) {
|
if(nread == -1) {
|
||||||
if(stream) {
|
remove_stream_read_timeout(stream);
|
||||||
remove_stream_read_timeout(stream);
|
remove_stream_write_timeout(stream);
|
||||||
remove_stream_write_timeout(stream);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE;
|
return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(nread == 0) {
|
if(nread == 0) {
|
||||||
*data_flags |= NGHTTP2_DATA_FLAG_EOF;
|
*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;
|
return nread;
|
||||||
|
@ -1215,8 +1221,9 @@ int hd_on_frame_recv_callback
|
||||||
|
|
||||||
if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
|
if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
|
||||||
remove_stream_read_timeout(stream);
|
remove_stream_read_timeout(stream);
|
||||||
|
if(!hd->get_config()->early_response) {
|
||||||
prepare_response(stream, hd);
|
prepare_response(stream, hd);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
add_stream_read_timeout(stream);
|
add_stream_read_timeout(stream);
|
||||||
}
|
}
|
||||||
|
@ -1250,12 +1257,17 @@ int hd_on_frame_recv_callback
|
||||||
hd->submit_rst_stream(stream, NGHTTP2_PROTOCOL_ERROR);
|
hd->submit_rst_stream(stream, NGHTTP2_PROTOCOL_ERROR);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(hd->get_config()->early_response) {
|
||||||
|
prepare_response(stream, hd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
|
if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
|
||||||
remove_stream_read_timeout(stream);
|
remove_stream_read_timeout(stream);
|
||||||
|
if(!hd->get_config()->early_response) {
|
||||||
prepare_response(stream, hd);
|
prepare_response(stream, hd);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
add_stream_read_timeout(stream);
|
add_stream_read_timeout(stream);
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,7 @@ struct Config {
|
||||||
bool verify_client;
|
bool verify_client;
|
||||||
bool no_tls;
|
bool no_tls;
|
||||||
bool error_gzip;
|
bool error_gzip;
|
||||||
|
bool early_response;
|
||||||
Config();
|
Config();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -137,6 +137,9 @@ Options:
|
||||||
Path to file that contains DH parameters in PEM
|
Path to file that contains DH parameters in PEM
|
||||||
format. Without this option, DHE cipher suites
|
format. Without this option, DHE cipher suites
|
||||||
are not available.
|
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.
|
--version Display version information and exit.
|
||||||
-h, --help Display this help and exit.)"
|
-h, --help Display this help and exit.)"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
@ -164,6 +167,7 @@ int main(int argc, char **argv)
|
||||||
{"color", no_argument, &flag, 2},
|
{"color", no_argument, &flag, 2},
|
||||||
{"version", no_argument, &flag, 3},
|
{"version", no_argument, &flag, 3},
|
||||||
{"dh-param-file", required_argument, &flag, 4},
|
{"dh-param-file", required_argument, &flag, 4},
|
||||||
|
{"early-response", no_argument, &flag, 5},
|
||||||
{nullptr, 0, nullptr, 0}
|
{nullptr, 0, nullptr, 0}
|
||||||
};
|
};
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
|
@ -242,6 +246,10 @@ int main(int argc, char **argv)
|
||||||
// dh-param-file
|
// dh-param-file
|
||||||
config.dh_param_file = optarg;
|
config.dh_param_file = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 5:
|
||||||
|
// early-response
|
||||||
|
config.early_response = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue