From cb73ba948d1edb35916500c7023a8d76558465fd Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 20 Dec 2015 23:47:16 +0900 Subject: [PATCH] Simplify HEADERS handling; handle push response in one function --- lib/nghttp2_session.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 67248904..c22216d2 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -3534,6 +3534,12 @@ int nghttp2_session_on_push_response_headers_received(nghttp2_session *session, "push response HEADERS: stream_id == 0"); } + if (session->server) { + return session_inflate_handle_invalid_connection( + session, frame, NGHTTP2_ERR_PROTO, + "HEADERS: no HEADERS allowed from client in reserved state"); + } + if (session_is_incoming_concurrent_streams_max(session)) { return session_inflate_handle_invalid_connection( session, frame, NGHTTP2_ERR_PROTO, @@ -3570,14 +3576,6 @@ int nghttp2_session_on_headers_received(nghttp2_session *session, return session_inflate_handle_invalid_connection( session, frame, NGHTTP2_ERR_PROTO, "HEADERS: stream_id == 0"); } - if (stream->state == NGHTTP2_STREAM_RESERVED) { - /* reserved. The valid push response HEADERS is processed by - nghttp2_session_on_push_response_headers_received(). This - generic HEADERS is called invalid cases for HEADERS against - reserved state. */ - return session_inflate_handle_invalid_connection( - session, frame, NGHTTP2_ERR_PROTO, "HEADERS: stream in reserved"); - } if ((stream->shut_flags & NGHTTP2_SHUT_RD)) { /* half closed (remote): from the spec: @@ -3634,22 +3632,18 @@ static int session_process_headers_frame(nghttp2_session *session) { return nghttp2_session_on_request_headers_received(session, frame); } - if (nghttp2_session_is_my_stream_id(session, frame->hd.stream_id)) { - if (stream->state == NGHTTP2_STREAM_OPENING) { - frame->headers.cat = NGHTTP2_HCAT_RESPONSE; - return nghttp2_session_on_response_headers_received(session, frame, - stream); - } - /* This handles the case when server received HEADERS for stream - in reserved stream from client. That is protocol error. */ - frame->headers.cat = NGHTTP2_HCAT_HEADERS; - return nghttp2_session_on_headers_received(session, frame, stream); - } if (stream->state == NGHTTP2_STREAM_RESERVED) { frame->headers.cat = NGHTTP2_HCAT_PUSH_RESPONSE; return nghttp2_session_on_push_response_headers_received(session, frame, stream); } + + if (stream->state == NGHTTP2_STREAM_OPENING && + nghttp2_session_is_my_stream_id(session, frame->hd.stream_id)) { + frame->headers.cat = NGHTTP2_HCAT_RESPONSE; + return nghttp2_session_on_response_headers_received(session, frame, stream); + } + frame->headers.cat = NGHTTP2_HCAT_HEADERS; return nghttp2_session_on_headers_received(session, frame, stream); }