nghttpd, nghttpx: Check END_STREAM flag in HEADERS other than request

This commit is contained in:
Tatsuhiro Tsujikawa 2014-05-24 15:02:46 +09:00
parent 9677788317
commit ebf0e4d787
2 changed files with 32 additions and 30 deletions

View File

@ -1258,13 +1258,13 @@ int hd_on_frame_recv_callback
break; break;
} }
case NGHTTP2_HEADERS: case NGHTTP2_HEADERS: {
switch(frame->headers.cat) { auto stream = hd->get_stream(frame->hd.stream_id);
case NGHTTP2_HCAT_REQUEST: { if(!stream) {
auto stream = hd->get_stream(frame->hd.stream_id); return 0;
if(!stream) { }
return 0;
} if(frame->headers.cat == NGHTTP2_HCAT_REQUEST) {
http2::normalize_headers(stream->headers); http2::normalize_headers(stream->headers);
if(!http2::check_http2_headers(stream->headers)) { if(!http2::check_http2_headers(stream->headers)) {
@ -1285,19 +1285,18 @@ 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(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) { }
remove_stream_read_timeout(stream);
prepare_response(stream, hd); if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
} else { remove_stream_read_timeout(stream);
add_stream_read_timeout(stream);
} prepare_response(stream, hd);
break; } else {
} add_stream_read_timeout(stream);
default:
break;
} }
break; break;
}
case NGHTTP2_SETTINGS: case NGHTTP2_SETTINGS:
if(frame->hd.flags & NGHTTP2_FLAG_ACK) { if(frame->hd.flags & NGHTTP2_FLAG_ACK) {
hd->remove_settings_timer(); hd->remove_settings_timer();

View File

@ -250,14 +250,11 @@ int on_begin_headers_callback(nghttp2_session *session,
namespace { namespace {
int on_request_headers(Http2Upstream *upstream, int on_request_headers(Http2Upstream *upstream,
Downstream *downstream,
nghttp2_session *session, nghttp2_session *session,
const nghttp2_frame *frame) const nghttp2_frame *frame)
{ {
int rv; int rv;
auto downstream = upstream->find_downstream(frame->hd.stream_id);
if(!downstream) {
return 0;
}
downstream->normalize_request_headers(); downstream->normalize_request_headers();
auto& nva = downstream->get_request_headers(); auto& nva = downstream->get_request_headers();
@ -358,12 +355,13 @@ int on_frame_recv_callback
verbose_on_frame_recv_callback(session, frame, user_data); verbose_on_frame_recv_callback(session, frame, user_data);
} }
auto upstream = static_cast<Http2Upstream*>(user_data); auto upstream = static_cast<Http2Upstream*>(user_data);
auto downstream = upstream->find_downstream(frame->hd.stream_id);
if(!downstream) {
return 0;
}
switch(frame->hd.type) { switch(frame->hd.type) {
case NGHTTP2_DATA: { case NGHTTP2_DATA: {
auto downstream = upstream->find_downstream(frame->hd.stream_id);
if(!downstream) {
break;
}
if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) { if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
downstream->end_upload_data(); downstream->end_upload_data();
downstream->set_request_state(Downstream::MSG_COMPLETE); downstream->set_request_state(Downstream::MSG_COMPLETE);
@ -371,12 +369,17 @@ int on_frame_recv_callback
break; break;
} }
case NGHTTP2_HEADERS: case NGHTTP2_HEADERS:
return on_request_headers(upstream, session, frame); if(frame->headers.cat == NGHTTP2_HCAT_REQUEST) {
case NGHTTP2_PRIORITY: { return on_request_headers(upstream, downstream, session, frame);
auto downstream = upstream->find_downstream(frame->hd.stream_id);
if(!downstream) {
break;
} }
if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
downstream->end_upload_data();
downstream->set_request_state(Downstream::MSG_COMPLETE);
}
break;
case NGHTTP2_PRIORITY: {
// TODO comment out for now // TODO comment out for now
// rv = downstream->change_priority(frame->priority.pri); // rv = downstream->change_priority(frame->priority.pri);
// if(rv != 0) { // if(rv != 0) {