@@ -102,7 +102,16 @@ where I: AsyncRead + AsyncWrite,
102
102
103
103
pub fn can_read_head ( & self ) -> bool {
104
104
match self . state . reading {
105
- Reading :: Init => true ,
105
+ Reading :: Init => {
106
+ if T :: should_read_first ( ) {
107
+ true
108
+ } else {
109
+ match self . state . writing {
110
+ Writing :: Init => false ,
111
+ _ => true ,
112
+ }
113
+ }
114
+ }
106
115
_ => false ,
107
116
}
108
117
}
@@ -840,25 +849,35 @@ mod tests {
840
849
841
850
#[ test]
842
851
fn test_conn_init_read_eof_busy ( ) {
843
- // server ignores
844
- let io = AsyncIo :: new_buf ( vec ! [ ] , 1 ) ;
845
- let mut conn = Conn :: < _ , proto:: Chunk , ServerTransaction > :: new ( io, Default :: default ( ) ) ;
846
- conn. state . busy ( ) ;
852
+ let _: Result < ( ) , ( ) > = future:: lazy ( || {
853
+ // server ignores
854
+ let io = AsyncIo :: new_buf ( vec ! [ ] , 1 ) ;
855
+ let mut conn = Conn :: < _ , proto:: Chunk , ServerTransaction > :: new ( io, Default :: default ( ) ) ;
856
+ conn. state . busy ( ) ;
847
857
848
- match conn. poll ( ) . unwrap ( ) {
849
- Async :: Ready ( None ) => { } ,
850
- other => panic ! ( "unexpected frame: {:?}" , other)
851
- }
858
+ match conn. poll ( ) . unwrap ( ) {
859
+ Async :: Ready ( None ) => { } ,
860
+ other => panic ! ( "unexpected frame: {:?}" , other)
861
+ }
852
862
853
- // client, when busy, returns the error
854
- let io = AsyncIo :: new_buf ( vec ! [ ] , 1 ) ;
855
- let mut conn = Conn :: < _ , proto:: Chunk , ClientTransaction > :: new ( io, Default :: default ( ) ) ;
856
- conn. state . busy ( ) ;
863
+ // client
864
+ let io = AsyncIo :: new_buf ( vec ! [ ] , 1 ) ;
865
+ let mut conn = Conn :: < _ , proto:: Chunk , ClientTransaction > :: new ( io, Default :: default ( ) ) ;
866
+ conn. state . busy ( ) ;
857
867
858
- match conn. poll ( ) {
859
- Err ( ref err) if err. kind ( ) == :: std:: io:: ErrorKind :: UnexpectedEof => { } ,
860
- other => panic ! ( "unexpected frame: {:?}" , other)
861
- }
868
+ match conn. poll ( ) {
869
+ Ok ( Async :: NotReady ) => { } ,
870
+ other => panic ! ( "unexpected frame: {:?}" , other)
871
+ }
872
+
873
+ // once mid-request, returns the error
874
+ conn. state . writing = super :: Writing :: KeepAlive ;
875
+ match conn. poll ( ) {
876
+ Err ( ref err) if err. kind ( ) == :: std:: io:: ErrorKind :: UnexpectedEof => { } ,
877
+ other => panic ! ( "unexpected frame: {:?}" , other)
878
+ }
879
+ Ok ( ( ) )
880
+ } ) . wait ( ) ;
862
881
}
863
882
864
883
#[ test]
0 commit comments