nghttpx: Don't respond DATA frame for HEAD request or 204, 304, 1xx
This commit is contained in:
parent
dd1850aed0
commit
c859fb8f7c
|
@ -851,4 +851,12 @@ void Downstream::reset_response_datalen()
|
|||
response_datalen_ = 0;
|
||||
}
|
||||
|
||||
bool Downstream::expect_response_body() const
|
||||
{
|
||||
return request_method_ != "HEAD" &&
|
||||
response_http_status_ / 100 != 1 &&
|
||||
response_http_status_ != 304 &&
|
||||
response_http_status_ != 204;
|
||||
}
|
||||
|
||||
} // namespace shrpx
|
||||
|
|
|
@ -144,6 +144,7 @@ public:
|
|||
int end_upload_data();
|
||||
size_t get_request_datalen() const;
|
||||
void reset_request_datalen();
|
||||
bool expect_response_body() const;
|
||||
enum {
|
||||
INITIAL,
|
||||
HEADER_COMPLETE,
|
||||
|
|
|
@ -1171,7 +1171,9 @@ int on_data_chunk_recv_callback(nghttp2_session *session,
|
|||
return 0;
|
||||
}
|
||||
auto downstream = sd->dconn->get_downstream();
|
||||
if(!downstream || downstream->get_downstream_stream_id() != stream_id) {
|
||||
if(!downstream || downstream->get_downstream_stream_id() != stream_id ||
|
||||
!downstream->expect_response_body()) {
|
||||
|
||||
http2session->submit_rst_stream(stream_id, NGHTTP2_INTERNAL_ERROR);
|
||||
|
||||
if(http2session->consume(stream_id, len) != 0) {
|
||||
|
|
|
@ -1219,8 +1219,16 @@ int Http2Upstream::on_downstream_header_complete(Downstream *downstream)
|
|||
data_prd.source.ptr = downstream;
|
||||
data_prd.read_callback = downstream_data_read_callback;
|
||||
|
||||
nghttp2_data_provider *data_prdptr;
|
||||
|
||||
if(downstream->expect_response_body()) {
|
||||
data_prdptr = &data_prd;
|
||||
} else {
|
||||
data_prdptr = nullptr;
|
||||
}
|
||||
|
||||
rv = nghttp2_submit_response(session_, downstream->get_stream_id(),
|
||||
nva.data(), nva.size(), &data_prd);
|
||||
nva.data(), nva.size(),data_prdptr);
|
||||
if(rv != 0) {
|
||||
ULOG(FATAL, this) << "nghttp2_submit_response() failed";
|
||||
return -1;
|
||||
|
|
Loading…
Reference in New Issue