@@ -233,13 +233,18 @@ impl Http1Transaction for Server {
233
233
) ;
234
234
debug_assert ! ( !msg. title_case_headers, "no server config for title case headers" ) ;
235
235
236
+ let mut wrote_len = false ;
237
+
236
238
// hyper currently doesn't support returning 1xx status codes as a Response
237
239
// This is because Service only allows returning a single Response, and
238
240
// so if you try to reply with a e.g. 100 Continue, you have no way of
239
241
// replying with the latter status code response.
240
- let is_upgrade = msg. head . subject == StatusCode :: SWITCHING_PROTOCOLS
241
- || ( msg. req_method == & Some ( Method :: CONNECT ) && msg. head . subject . is_success ( ) ) ;
242
- let ( ret, mut is_last) = if is_upgrade {
242
+ let ( ret, mut is_last) = if msg. head . subject == StatusCode :: SWITCHING_PROTOCOLS {
243
+ ( Ok ( ( ) ) , true )
244
+ } else if msg. req_method == & Some ( Method :: CONNECT ) && msg. head . subject . is_success ( ) {
245
+ // Sending content-length or transfer-encoding header on 2xx response
246
+ // to CONNECT is forbidden in RFC 7231.
247
+ wrote_len = true ;
243
248
( Ok ( ( ) ) , true )
244
249
} else if msg. head . subject . is_informational ( ) {
245
250
warn ! ( "response with 1xx status code not supported" ) ;
@@ -282,13 +287,12 @@ impl Http1Transaction for Server {
282
287
}
283
288
284
289
let mut encoder = Encoder :: length ( 0 ) ;
285
- let mut wrote_len = false ;
286
290
let mut wrote_date = false ;
287
291
' headers: for ( name, mut values) in msg. head . headers . drain ( ) {
288
292
match name {
289
293
header:: CONTENT_LENGTH => {
290
294
if wrote_len {
291
- warn ! ( "transfer-encoding and content-length both found, canceling" ) ;
295
+ warn ! ( "unexpected content-length found, canceling" ) ;
292
296
rewind ( dst) ;
293
297
return Err ( :: Error :: new_header ( ) ) ;
294
298
}
@@ -397,7 +401,7 @@ impl Http1Transaction for Server {
397
401
} ,
398
402
header:: TRANSFER_ENCODING => {
399
403
if wrote_len {
400
- warn ! ( "transfer-encoding and content-length both found, canceling" ) ;
404
+ warn ! ( "unexpected transfer-encoding found, canceling" ) ;
401
405
rewind ( dst) ;
402
406
return Err ( :: Error :: new_header ( ) ) ;
403
407
}
0 commit comments