@@ -7,10 +7,10 @@ use futures::task::Task;
7
7
use tokio_io:: { AsyncRead , AsyncWrite } ;
8
8
use tokio_proto:: streaming:: pipeline:: { Frame , Transport } ;
9
9
10
- use header:: { ContentLength , TransferEncoding } ;
11
10
use http:: { self , Http1Transaction , DebugTruncate } ;
12
11
use http:: io:: { Cursor , Buffered } ;
13
12
use http:: h1:: { Encoder , Decoder } ;
13
+ use method:: Method ;
14
14
use version:: HttpVersion ;
15
15
16
16
@@ -37,10 +37,11 @@ where I: AsyncRead + AsyncWrite,
37
37
Conn {
38
38
io : Buffered :: new ( io) ,
39
39
state : State {
40
+ keep_alive : keep_alive,
41
+ method : None ,
42
+ read_task : None ,
40
43
reading : Reading :: Init ,
41
44
writing : Writing :: Init ,
42
- read_task : None ,
43
- keep_alive : keep_alive,
44
45
} ,
45
46
_marker : PhantomData ,
46
47
}
@@ -103,7 +104,7 @@ where I: AsyncRead + AsyncWrite,
103
104
104
105
match version {
105
106
HttpVersion :: Http10 | HttpVersion :: Http11 => {
106
- let decoder = match T :: decoder ( & head) {
107
+ let decoder = match T :: decoder ( & head, & mut self . state . method ) {
107
108
Ok ( d) => d,
108
109
Err ( e) => {
109
110
debug ! ( "decoder error = {:?}" , e) ;
@@ -234,17 +235,8 @@ where I: AsyncRead + AsyncWrite,
234
235
}
235
236
}
236
237
237
- fn write_head ( & mut self , mut head : http:: MessageHead < T :: Outgoing > , body : bool ) {
238
+ fn write_head ( & mut self , head : http:: MessageHead < T :: Outgoing > , body : bool ) {
238
239
debug_assert ! ( self . can_write_head( ) ) ;
239
- if !body {
240
- head. headers . remove :: < TransferEncoding > ( ) ;
241
- //TODO: check that this isn't a response to a HEAD
242
- //request, which could include the content-length
243
- //even if no body is to be written
244
- if T :: should_set_length ( & head) {
245
- head. headers . set ( ContentLength ( 0 ) ) ;
246
- }
247
- }
248
240
249
241
let wants_keep_alive = head. should_keep_alive ( ) ;
250
242
self . state . keep_alive &= wants_keep_alive;
@@ -256,8 +248,8 @@ where I: AsyncRead + AsyncWrite,
256
248
buf. extend_from_slice ( pending. buf ( ) ) ;
257
249
}
258
250
}
259
- let encoder = T :: encode ( head, buf) ;
260
- self . state . writing = if body {
251
+ let encoder = T :: encode ( head, body , & mut self . state . method , buf) ;
252
+ self . state . writing = if !encoder . is_eof ( ) {
261
253
Writing :: Body ( encoder, None )
262
254
} else {
263
255
Writing :: KeepAlive
@@ -493,10 +485,11 @@ impl<I, B: AsRef<[u8]>, T, K: fmt::Debug> fmt::Debug for Conn<I, B, T, K> {
493
485
}
494
486
495
487
struct State < B , K > {
488
+ keep_alive : K ,
489
+ method : Option < Method > ,
490
+ read_task : Option < Task > ,
496
491
reading : Reading ,
497
492
writing : Writing < B > ,
498
- read_task : Option < Task > ,
499
- keep_alive : K ,
500
493
}
501
494
502
495
#[ derive( Debug ) ]
@@ -522,6 +515,7 @@ impl<B: AsRef<[u8]>, K: fmt::Debug> fmt::Debug for State<B, K> {
522
515
. field ( "reading" , & self . reading )
523
516
. field ( "writing" , & self . writing )
524
517
. field ( "keep_alive" , & self . keep_alive )
518
+ . field ( "method" , & self . method )
525
519
. field ( "read_task" , & self . read_task )
526
520
. finish ( )
527
521
}
@@ -641,6 +635,7 @@ impl<B, K: KeepAlive> State<B, K> {
641
635
}
642
636
643
637
fn idle ( & mut self ) {
638
+ self . method = None ;
644
639
self . reading = Reading :: Init ;
645
640
self . writing = Writing :: Init ;
646
641
self . keep_alive . idle ( ) ;
0 commit comments