@@ -113,7 +113,7 @@ static int check_path(nghttp2_stream *stream) {
113113}
114114
115115static int http_request_on_header (nghttp2_stream * stream , nghttp2_hd_nv * nv ,
116- int trailer ) {
116+ int trailer , int connect_protocol ) {
117117 if (nv -> name -> base [0 ] == ':' ) {
118118 if (trailer ||
119119 (stream -> http_flags & NGHTTP2_HTTP_FLAG_PSEUDO_HEADER_DISALLOWED )) {
@@ -146,10 +146,6 @@ static int http_request_on_header(nghttp2_stream *stream, nghttp2_hd_nv *nv,
146146 return NGHTTP2_ERR_HTTP_HEADER ;
147147 }
148148 stream -> http_flags |= NGHTTP2_HTTP_FLAG_METH_CONNECT ;
149- if (stream -> http_flags &
150- (NGHTTP2_HTTP_FLAG__PATH | NGHTTP2_HTTP_FLAG__SCHEME )) {
151- return NGHTTP2_ERR_HTTP_HEADER ;
152- }
153149 }
154150 break ;
155151 case 'S' :
@@ -162,9 +158,6 @@ static int http_request_on_header(nghttp2_stream *stream, nghttp2_hd_nv *nv,
162158 }
163159 break ;
164160 case NGHTTP2_TOKEN__PATH :
165- if (stream -> http_flags & NGHTTP2_HTTP_FLAG_METH_CONNECT ) {
166- return NGHTTP2_ERR_HTTP_HEADER ;
167- }
168161 if (!check_pseudo_header (stream , nv , NGHTTP2_HTTP_FLAG__PATH )) {
169162 return NGHTTP2_ERR_HTTP_HEADER ;
170163 }
@@ -175,9 +168,6 @@ static int http_request_on_header(nghttp2_stream *stream, nghttp2_hd_nv *nv,
175168 }
176169 break ;
177170 case NGHTTP2_TOKEN__SCHEME :
178- if (stream -> http_flags & NGHTTP2_HTTP_FLAG_METH_CONNECT ) {
179- return NGHTTP2_ERR_HTTP_HEADER ;
180- }
181171 if (!check_pseudo_header (stream , nv , NGHTTP2_HTTP_FLAG__SCHEME )) {
182172 return NGHTTP2_ERR_HTTP_HEADER ;
183173 }
@@ -186,6 +176,15 @@ static int http_request_on_header(nghttp2_stream *stream, nghttp2_hd_nv *nv,
186176 stream -> http_flags |= NGHTTP2_HTTP_FLAG_SCHEME_HTTP ;
187177 }
188178 break ;
179+ case NGHTTP2_TOKEN__PROTOCOL :
180+ if (!connect_protocol ) {
181+ return NGHTTP2_ERR_HTTP_HEADER ;
182+ }
183+
184+ if (!check_pseudo_header (stream , nv , NGHTTP2_HTTP_FLAG__PROTOCOL )) {
185+ return NGHTTP2_ERR_HTTP_HEADER ;
186+ }
187+ break ;
189188 case NGHTTP2_TOKEN_HOST :
190189 if (!check_pseudo_header (stream , nv , NGHTTP2_HTTP_FLAG_HOST )) {
191190 return NGHTTP2_ERR_HTTP_HEADER ;
@@ -265,7 +264,7 @@ static int http_response_on_header(nghttp2_stream *stream, nghttp2_hd_nv *nv,
265264 return NGHTTP2_ERR_REMOVE_HTTP_HEADER ;
266265 }
267266 if (stream -> status_code / 100 == 1 ||
268- (stream -> status_code == 200 &&
267+ (stream -> status_code / 100 == 2 &&
269268 (stream -> http_flags & NGHTTP2_HTTP_FLAG_METH_CONNECT ))) {
270269 return NGHTTP2_ERR_HTTP_HEADER ;
271270 }
@@ -458,16 +457,21 @@ int nghttp2_http_on_header(nghttp2_session *session, nghttp2_stream *stream,
458457 }
459458
460459 if (session -> server || frame -> hd .type == NGHTTP2_PUSH_PROMISE ) {
461- return http_request_on_header (stream , nv , trailer );
460+ return http_request_on_header (stream , nv , trailer ,
461+ session -> server &&
462+ session -> pending_enable_connect_protocol );
462463 }
463464
464465 return http_response_on_header (stream , nv , trailer );
465466}
466467
467468int nghttp2_http_on_request_headers (nghttp2_stream * stream ,
468469 nghttp2_frame * frame ) {
469- if (stream -> http_flags & NGHTTP2_HTTP_FLAG_METH_CONNECT ) {
470- if ((stream -> http_flags & NGHTTP2_HTTP_FLAG__AUTHORITY ) == 0 ) {
470+ if (!(stream -> http_flags & NGHTTP2_HTTP_FLAG__PROTOCOL ) &&
471+ (stream -> http_flags & NGHTTP2_HTTP_FLAG_METH_CONNECT )) {
472+ if ((stream -> http_flags &
473+ (NGHTTP2_HTTP_FLAG__SCHEME | NGHTTP2_HTTP_FLAG__PATH )) ||
474+ (stream -> http_flags & NGHTTP2_HTTP_FLAG__AUTHORITY ) == 0 ) {
471475 return -1 ;
472476 }
473477 stream -> content_length = -1 ;
@@ -478,6 +482,11 @@ int nghttp2_http_on_request_headers(nghttp2_stream *stream,
478482 (NGHTTP2_HTTP_FLAG__AUTHORITY | NGHTTP2_HTTP_FLAG_HOST )) == 0 ) {
479483 return -1 ;
480484 }
485+ if ((stream -> http_flags & NGHTTP2_HTTP_FLAG__PROTOCOL ) &&
486+ ((stream -> http_flags & NGHTTP2_HTTP_FLAG_METH_CONNECT ) == 0 ||
487+ (stream -> http_flags & NGHTTP2_HTTP_FLAG__AUTHORITY ) == 0 )) {
488+ return -1 ;
489+ }
481490 if (!check_path (stream )) {
482491 return -1 ;
483492 }
0 commit comments