File tree 4 files changed +41
-4
lines changed
4 files changed +41
-4
lines changed Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ where
108
108
}
109
109
let ( head, body) = req. into_parts ( ) ;
110
110
let mut req = :: http:: Request :: from_parts ( head, ( ) ) ;
111
- super :: strip_connection_headers ( req. headers_mut ( ) ) ;
111
+ super :: strip_connection_headers ( req. headers_mut ( ) , true ) ;
112
112
if let Some ( len) = body. content_length ( ) {
113
113
headers:: set_content_length_if_missing ( req. headers_mut ( ) , len) ;
114
114
}
Original file line number Diff line number Diff line change @@ -15,15 +15,17 @@ mod server;
15
15
pub ( crate ) use self :: client:: Client ;
16
16
pub ( crate ) use self :: server:: Server ;
17
17
18
- fn strip_connection_headers ( headers : & mut HeaderMap ) {
18
+ fn strip_connection_headers ( headers : & mut HeaderMap , is_request : bool ) {
19
19
// List of connection headers from:
20
20
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Connection
21
+ //
22
+ // TE headers are allowed in HTTP/2 requests as long as the value is "trailers", so they're
23
+ // tested separately.
21
24
let connection_headers = [
22
25
HeaderName :: from_lowercase ( b"keep-alive" ) . unwrap ( ) ,
23
26
HeaderName :: from_lowercase ( b"proxy-connection" ) . unwrap ( ) ,
24
27
PROXY_AUTHENTICATE ,
25
28
PROXY_AUTHORIZATION ,
26
- TE ,
27
29
TRAILER ,
28
30
TRANSFER_ENCODING ,
29
31
UPGRADE ,
@@ -35,6 +37,17 @@ fn strip_connection_headers(headers: &mut HeaderMap) {
35
37
}
36
38
}
37
39
40
+ if is_request {
41
+ if headers. get ( TE ) . map ( |te_header| te_header != "trailers" ) . unwrap_or ( false ) {
42
+ warn ! ( "TE headers not set to \" trailers\" are illegal in HTTP/2 requests" ) ;
43
+ headers. remove ( TE ) ;
44
+ }
45
+ } else {
46
+ if headers. remove ( TE ) . is_some ( ) {
47
+ warn ! ( "TE headers illegal in HTTP/2 responses" ) ;
48
+ }
49
+ }
50
+
38
51
if let Some ( header) = headers. remove ( CONNECTION ) {
39
52
warn ! (
40
53
"Connection header illegal in HTTP/2: {}" ,
Original file line number Diff line number Diff line change @@ -192,7 +192,7 @@ where
192
192
193
193
let ( head, body) = res. into_parts ( ) ;
194
194
let mut res = :: http:: Response :: from_parts ( head, ( ) ) ;
195
- super :: strip_connection_headers ( res. headers_mut ( ) ) ;
195
+ super :: strip_connection_headers ( res. headers_mut ( ) , false ) ;
196
196
if let Some ( len) = body. content_length ( ) {
197
197
headers:: set_content_length_if_missing ( res. headers_mut ( ) , len) ;
198
198
}
Original file line number Diff line number Diff line change @@ -184,6 +184,30 @@ t! {
184
184
;
185
185
}
186
186
187
+ t ! {
188
+ get_allow_te_trailers_header,
189
+ client:
190
+ request:
191
+ uri: "/" ,
192
+ headers: {
193
+ // http2 strips connection headers other than TE "trailers"
194
+ "te" => "trailers" ,
195
+ } ,
196
+ ;
197
+ response:
198
+ status: 200 ,
199
+ ;
200
+ server:
201
+ request:
202
+ uri: "/" ,
203
+ headers: {
204
+ "te" => "trailers" ,
205
+ } ,
206
+ ;
207
+ response:
208
+ ;
209
+ }
210
+
187
211
t ! {
188
212
get_body_chunked,
189
213
client:
You can’t perform that action at this time.
0 commit comments