From 334c439ce05b721963be56341348c1d58289051a Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 4 Oct 2018 11:56:13 +0900 Subject: [PATCH] Fix bug that regular CONNECT does not work --- lib/nghttp2_http.c | 5 ++--- lib/nghttp2_http.h | 6 ++---- lib/nghttp2_session.c | 8 ++------ tests/nghttp2_session_test.c | 8 ++++++++ 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/nghttp2_http.c b/lib/nghttp2_http.c index ba6ff35f..6e8acfdc 100644 --- a/lib/nghttp2_http.c +++ b/lib/nghttp2_http.c @@ -466,9 +466,8 @@ int nghttp2_http_on_header(nghttp2_session *session, nghttp2_stream *stream, } int nghttp2_http_on_request_headers(nghttp2_stream *stream, - nghttp2_frame *frame, - int connect_protocol) { - if (!connect_protocol && + nghttp2_frame *frame) { + if (!(stream->http_flags & NGHTTP2_HTTP_FLAG__PROTOCOL) && (stream->http_flags & NGHTTP2_HTTP_FLAG_METH_CONNECT)) { if ((stream->http_flags & (NGHTTP2_HTTP_FLAG__SCHEME | NGHTTP2_HTTP_FLAG__PATH)) || diff --git a/lib/nghttp2_http.h b/lib/nghttp2_http.h index c747675f..dd057cdb 100644 --- a/lib/nghttp2_http.h +++ b/lib/nghttp2_http.h @@ -52,13 +52,11 @@ int nghttp2_http_on_header(nghttp2_session *session, nghttp2_stream *stream, int trailer); /* - * This function is called when request header is received. - * |connect_protocol| is nonzero if SETTINGS_ENABLE_CONNECT_PROTOCOL - * is enabled by the local endpoint (which must be server). This + * This function is called when request header is received. This * function performs validation and returns 0 if it succeeds, or -1. */ int nghttp2_http_on_request_headers(nghttp2_stream *stream, - nghttp2_frame *frame, int connect_protocol); + nghttp2_frame *frame); /* * This function is called when response header is received. This diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 8d9c8fa4..ef4932af 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -3746,17 +3746,13 @@ static int session_after_header_block_received(nghttp2_session *session) { subject_stream = nghttp2_session_get_stream( session, frame->push_promise.promised_stream_id); if (subject_stream) { - rv = nghttp2_http_on_request_headers( - subject_stream, frame, - session->server && session->pending_enable_connect_protocol); + rv = nghttp2_http_on_request_headers(subject_stream, frame); } } else { assert(frame->hd.type == NGHTTP2_HEADERS); switch (frame->headers.cat) { case NGHTTP2_HCAT_REQUEST: - rv = nghttp2_http_on_request_headers( - stream, frame, - session->server && session->pending_enable_connect_protocol); + rv = nghttp2_http_on_request_headers(stream, frame); break; case NGHTTP2_HCAT_RESPONSE: case NGHTTP2_HCAT_PUSH_RESPONSE: diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index f02dfb39..296fb9d1 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -10922,6 +10922,8 @@ void test_nghttp2_http_mandatory_headers(void) { MAKE_NV(":scheme", "http"), MAKE_NV(":path", "/"), MAKE_NV(":method", "CONNECT"), MAKE_NV("host", "localhost"), MAKE_NV(":protocol", "websocket")}; + const nghttp2_nv regularconnect_reqnv[] = { + MAKE_NV(":method", "CONNECT"), MAKE_NV(":authority", "localhost")}; mem = nghttp2_mem_default(); @@ -11107,6 +11109,12 @@ void test_nghttp2_http_mandatory_headers(void) { connectprotonoauth_reqnv, ARRLEN(connectprotonoauth_reqnv)); + /* regular CONNECT method should succeed with + SETTINGS_CONNECT_PROTOCOL */ + check_nghttp2_http_recv_headers_ok(session, &deflater, 9, -1, + regularconnect_reqnv, + ARRLEN(regularconnect_reqnv)); + nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session);