@@ -12,7 +12,7 @@ use method::Method;
12
12
use status:: StatusCode ;
13
13
use uri:: RequestUri ;
14
14
use version:: HttpVersion :: { self , Http10 , Http11 } ;
15
- use HttpError :: HttpTooLargeError ;
15
+ use HttpError :: { HttpIoError , HttpTooLargeError } ;
16
16
use { HttpError , HttpResult } ;
17
17
18
18
use self :: HttpReader :: { SizedReader , ChunkedReader , EofReader , EmptyReader } ;
@@ -353,6 +353,12 @@ fn parse<R: Read, T: TryParse<Subject=I>, I>(rdr: &mut BufReader<R>) -> HttpResu
353
353
_partial => ( )
354
354
}
355
355
match try!( rdr. read_into_buf ( ) ) {
356
+ 0 if rdr. get_buf ( ) . len ( ) == 0 => {
357
+ return Err ( HttpIoError ( io:: Error :: new (
358
+ io:: ErrorKind :: ConnectionAborted ,
359
+ "Connection closed"
360
+ ) ) )
361
+ } ,
356
362
0 => return Err ( HttpTooLargeError ) ,
357
363
_ => ( )
358
364
}
@@ -417,6 +423,7 @@ impl<'a> TryParse for httparse::Response<'a> {
417
423
}
418
424
419
425
/// An Incoming Message head. Includes request/status line, and headers.
426
+ #[ derive( Debug ) ]
420
427
pub struct Incoming < S > {
421
428
/// HTTP version of the message.
422
429
pub version : HttpVersion ,
@@ -440,8 +447,10 @@ pub struct RawStatus(pub u16, pub Cow<'static, str>);
440
447
mod tests {
441
448
use std:: io:: { self , Write } ;
442
449
443
- use super :: { read_chunk_size} ;
450
+ use buffer:: BufReader ;
451
+ use mock:: MockStream ;
444
452
453
+ use super :: { read_chunk_size, parse_request} ;
445
454
446
455
#[ test]
447
456
fn test_write_chunked ( ) {
@@ -509,25 +518,30 @@ mod tests {
509
518
510
519
#[ test]
511
520
fn test_parse_incoming ( ) {
512
- use buffer:: BufReader ;
513
- use mock:: MockStream ;
514
-
515
- use super :: parse_request;
516
521
let mut raw = MockStream :: with_input ( b"GET /echo HTTP/1.1\r \n Host: hyper.rs\r \n \r \n " ) ;
517
522
let mut buf = BufReader :: new ( & mut raw) ;
518
523
parse_request ( & mut buf) . unwrap ( ) ;
519
524
}
520
525
526
+ #[ test]
527
+ fn test_parse_tcp_closed ( ) {
528
+ use std:: io:: ErrorKind ;
529
+ use error:: HttpError :: HttpIoError ;
530
+
531
+ let mut empty = MockStream :: new ( ) ;
532
+ let mut buf = BufReader :: new ( & mut empty) ;
533
+ match parse_request ( & mut buf) {
534
+ Err ( HttpIoError ( ref e) ) if e. kind ( ) == ErrorKind :: ConnectionAborted => ( ) ,
535
+ other => panic ! ( "unexpected result: {:?}" , other)
536
+ }
537
+ }
538
+
521
539
#[ cfg( feature = "nightly" ) ]
522
540
use test:: Bencher ;
523
541
524
542
#[ cfg( feature = "nightly" ) ]
525
543
#[ bench]
526
544
fn bench_parse_incoming ( b : & mut Bencher ) {
527
- use buffer:: BufReader ;
528
- use mock:: MockStream ;
529
-
530
- use super :: parse_request;
531
545
let mut raw = MockStream :: with_input ( b"GET /echo HTTP/1.1\r \n Host: hyper.rs\r \n \r \n " ) ;
532
546
let mut buf = BufReader :: new ( & mut raw) ;
533
547
b. iter ( || {
0 commit comments