@@ -113,7 +113,7 @@ static int check_path(nghttp2_stream *stream) {
113
113
}
114
114
115
115
static int http_request_on_header (nghttp2_stream * stream , nghttp2_hd_nv * nv ,
116
- int trailer ) {
116
+ int trailer , int connect_protocol ) {
117
117
if (nv -> name -> base [0 ] == ':' ) {
118
118
if (trailer ||
119
119
(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,
146
146
return NGHTTP2_ERR_HTTP_HEADER ;
147
147
}
148
148
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
- }
153
149
}
154
150
break ;
155
151
case 'S' :
@@ -162,9 +158,6 @@ static int http_request_on_header(nghttp2_stream *stream, nghttp2_hd_nv *nv,
162
158
}
163
159
break ;
164
160
case NGHTTP2_TOKEN__PATH :
165
- if (stream -> http_flags & NGHTTP2_HTTP_FLAG_METH_CONNECT ) {
166
- return NGHTTP2_ERR_HTTP_HEADER ;
167
- }
168
161
if (!check_pseudo_header (stream , nv , NGHTTP2_HTTP_FLAG__PATH )) {
169
162
return NGHTTP2_ERR_HTTP_HEADER ;
170
163
}
@@ -175,9 +168,6 @@ static int http_request_on_header(nghttp2_stream *stream, nghttp2_hd_nv *nv,
175
168
}
176
169
break ;
177
170
case NGHTTP2_TOKEN__SCHEME :
178
- if (stream -> http_flags & NGHTTP2_HTTP_FLAG_METH_CONNECT ) {
179
- return NGHTTP2_ERR_HTTP_HEADER ;
180
- }
181
171
if (!check_pseudo_header (stream , nv , NGHTTP2_HTTP_FLAG__SCHEME )) {
182
172
return NGHTTP2_ERR_HTTP_HEADER ;
183
173
}
@@ -186,6 +176,15 @@ static int http_request_on_header(nghttp2_stream *stream, nghttp2_hd_nv *nv,
186
176
stream -> http_flags |= NGHTTP2_HTTP_FLAG_SCHEME_HTTP ;
187
177
}
188
178
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 ;
189
188
case NGHTTP2_TOKEN_HOST :
190
189
if (!check_pseudo_header (stream , nv , NGHTTP2_HTTP_FLAG_HOST )) {
191
190
return NGHTTP2_ERR_HTTP_HEADER ;
@@ -265,7 +264,7 @@ static int http_response_on_header(nghttp2_stream *stream, nghttp2_hd_nv *nv,
265
264
return NGHTTP2_ERR_REMOVE_HTTP_HEADER ;
266
265
}
267
266
if (stream -> status_code / 100 == 1 ||
268
- (stream -> status_code == 200 &&
267
+ (stream -> status_code / 100 == 2 &&
269
268
(stream -> http_flags & NGHTTP2_HTTP_FLAG_METH_CONNECT ))) {
270
269
return NGHTTP2_ERR_HTTP_HEADER ;
271
270
}
@@ -458,16 +457,21 @@ int nghttp2_http_on_header(nghttp2_session *session, nghttp2_stream *stream,
458
457
}
459
458
460
459
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 );
462
463
}
463
464
464
465
return http_response_on_header (stream , nv , trailer );
465
466
}
466
467
467
468
int nghttp2_http_on_request_headers (nghttp2_stream * stream ,
468
469
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 ) {
471
475
return -1 ;
472
476
}
473
477
stream -> content_length = -1 ;
@@ -478,6 +482,11 @@ int nghttp2_http_on_request_headers(nghttp2_stream *stream,
478
482
(NGHTTP2_HTTP_FLAG__AUTHORITY | NGHTTP2_HTTP_FLAG_HOST )) == 0 ) {
479
483
return -1 ;
480
484
}
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
+ }
481
490
if (!check_path (stream )) {
482
491
return -1 ;
483
492
}
0 commit comments