nghttpx: Require content-length in HTTP2 upstream if END_STREAM flag is not set

This commit is contained in:
Tatsuhiro Tsujikawa 2013-08-21 01:11:08 +09:00
parent 823bb6c35e
commit b8a01f5212
1 changed files with 13 additions and 2 deletions

View File

@ -208,7 +208,8 @@ void on_frame_recv_callback
}
// Assuming that nva is sorted by name.
const char *req_headers[] = {":host", ":method", ":path", ":scheme" };
const char *req_headers[] = {":host", ":method", ":path", ":scheme",
"content-length"};
const size_t req_hdlen = sizeof(req_headers)/sizeof(req_headers[0]);
int req_hdidx[req_hdlen];
memset(req_hdidx, -1, sizeof(req_hdidx));
@ -243,13 +244,23 @@ void on_frame_recv_callback
}
if(!bad_req) {
// Here :scheme is optional, because with CONNECT method, it
// is omitted.
// is omitted. content-length is mandatory if END_STREAM is
// not set.
for(j = 0; j < 3; ++j) {
if(req_hdidx[j] == -1) {
bad_req = true;
break;
}
}
if((frame->hd.flags & NGHTTP2_FLAG_END_STREAM) == 0 &&
req_hdidx[4] == -1) {
// If content-length is missing,
// Downstream::push_upload_data_chunk will fail and
// RST_STREAM will be sent. Therefore, error reply in
// HEADERS may not be sent. So just issue RST_STREAM here.
upstream->rst_stream(downstream, NGHTTP2_PROTOCOL_ERROR);
return;
}
}
if(!bad_req) {
for(; i < frame->headers.nvlen; ++i) {