From 651e14771182e2292833d84ab513e5f018df51c2 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 28 Sep 2018 00:11:33 +0900 Subject: [PATCH] Allow client sending :protocol optimistically --- lib/nghttp2_http.c | 6 +++--- lib/nghttp2_session.c | 11 +++++++++-- lib/nghttp2_session.h | 3 +++ tests/nghttp2_session_test.c | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/nghttp2_http.c b/lib/nghttp2_http.c index 0c3a3712..0f1c5c5f 100644 --- a/lib/nghttp2_http.c +++ b/lib/nghttp2_http.c @@ -457,9 +457,9 @@ int nghttp2_http_on_header(nghttp2_session *session, nghttp2_stream *stream, } if (session->server || frame->hd.type == NGHTTP2_PUSH_PROMISE) { - return http_request_on_header( - stream, nv, trailer, - session->server && session->local_settings.enable_connect_protocol); + return http_request_on_header(stream, nv, trailer, + session->server && + session->pending_enable_connect_protocol); } return http_response_on_header(stream, nv, trailer); diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 36e372bc..8d9c8fa4 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -3748,7 +3748,7 @@ static int session_after_header_block_received(nghttp2_session *session) { if (subject_stream) { rv = nghttp2_http_on_request_headers( subject_stream, frame, - session->server && session->local_settings.enable_connect_protocol); + session->server && session->pending_enable_connect_protocol); } } else { assert(frame->hd.type == NGHTTP2_HEADERS); @@ -3756,7 +3756,7 @@ static int session_after_header_block_received(nghttp2_session *session) { case NGHTTP2_HCAT_REQUEST: rv = nghttp2_http_on_request_headers( stream, frame, - session->server && session->local_settings.enable_connect_protocol); + session->server && session->pending_enable_connect_protocol); break; case NGHTTP2_HCAT_RESPONSE: case NGHTTP2_HCAT_PUSH_RESPONSE: @@ -7080,6 +7080,13 @@ int nghttp2_session_add_settings(nghttp2_session *session, uint8_t flags, } } + for (i = niv; i > 0; --i) { + if (iv[i - 1].settings_id == NGHTTP2_SETTINGS_ENABLE_CONNECT_PROTOCOL) { + session->pending_enable_connect_protocol = (uint8_t)iv[i - 1].value; + break; + } + } + return 0; } diff --git a/lib/nghttp2_session.h b/lib/nghttp2_session.h index 95c2afb7..40a8865a 100644 --- a/lib/nghttp2_session.h +++ b/lib/nghttp2_session.h @@ -322,6 +322,9 @@ struct nghttp2_session { /* Unacked local ENABLE_PUSH value. We use this to refuse PUSH_PROMISE before SETTINGS ACK is received. */ uint8_t pending_enable_push; + /* Unacked local ENABLE_CONNECT_PROTOCOL value. We use this to + accept :protocol header field before SETTINGS_ACK is received. */ + uint8_t pending_enable_connect_protocol; /* Nonzero if the session is server side. */ uint8_t server; /* Flags indicating GOAWAY is sent and/or received. The flags are diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index 956ff6f7..f02dfb39 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -11082,7 +11082,7 @@ void test_nghttp2_http_mandatory_headers(void) { /* enable SETTINGS_CONNECT_PROTOCOL */ nghttp2_session_server_new(&session, &callbacks, &ud); - session->local_settings.enable_connect_protocol = 1; + session->pending_enable_connect_protocol = 1; nghttp2_hd_deflate_init(&deflater, mem);