@@ -10,7 +10,7 @@ use proto::{MessageHead, RawStatus, Http1Transaction, ParseResult,
10
10
use proto:: h1:: { Encoder , Decoder , date} ;
11
11
use method:: Method ;
12
12
use status:: StatusCode ;
13
- use version:: HttpVersion :: { self , Http10 , Http11 } ;
13
+ use version:: HttpVersion :: { Http10 , Http11 } ;
14
14
15
15
const MAX_HEADERS : usize = 100 ;
16
16
const AVERAGE_HEADER_SIZE : usize = 30 ; // totally scientific
@@ -203,7 +203,7 @@ impl ServerTransaction {
203
203
} ;
204
204
205
205
if has_body && can_have_body {
206
- set_length ( head . version , & mut head. headers )
206
+ set_length ( & mut head. headers , head . version == Http11 )
207
207
} else {
208
208
head. headers . remove :: < TransferEncoding > ( ) ;
209
209
if can_have_body {
@@ -354,7 +354,11 @@ impl Http1Transaction for ClientTransaction {
354
354
impl ClientTransaction {
355
355
fn set_length ( head : & mut RequestHead , has_body : bool ) -> Encoder {
356
356
if has_body {
357
- set_length ( head. version , & mut head. headers )
357
+ let can_chunked = head. version == Http11
358
+ && ( head. subject . 0 != Method :: Head )
359
+ && ( head. subject . 0 != Method :: Get )
360
+ && ( head. subject . 0 != Method :: Connect ) ;
361
+ set_length ( & mut head. headers , can_chunked)
358
362
} else {
359
363
head. headers . remove :: < ContentLength > ( ) ;
360
364
head. headers . remove :: < TransferEncoding > ( ) ;
@@ -363,12 +367,12 @@ impl ClientTransaction {
363
367
}
364
368
}
365
369
366
- fn set_length ( version : HttpVersion , headers : & mut Headers ) -> Encoder {
370
+ fn set_length ( headers : & mut Headers , can_chunked : bool ) -> Encoder {
367
371
let len = headers. get :: < header:: ContentLength > ( ) . map ( |n| * * n) ;
368
372
369
373
if let Some ( len) = len {
370
374
Encoder :: length ( len)
371
- } else if version == Http11 {
375
+ } else if can_chunked {
372
376
let encodings = match headers. get_mut :: < header:: TransferEncoding > ( ) {
373
377
Some ( & mut header:: TransferEncoding ( ref mut encodings) ) => {
374
378
if encodings. last ( ) != Some ( & header:: Encoding :: Chunked ) {
0 commit comments