@@ -609,11 +609,11 @@ pub fn read_status<R: Reader>(stream: &mut R) -> HttpResult<RawStatus> {
609
609
_ => return Err ( HttpStatusError )
610
610
}
611
611
612
- let mut buf = [ b' ' , ..16 ] ;
612
+ let mut buf = [ b' ' , ..32 ] ;
613
613
614
614
{
615
615
let mut bufwrt = BufWriter :: new ( & mut buf) ;
616
- loop {
616
+ ' read : loop {
617
617
match try!( stream. read_byte ( ) ) {
618
618
CR => match try!( stream. read_byte ( ) ) {
619
619
LF => break ,
@@ -622,8 +622,16 @@ pub fn read_status<R: Reader>(stream: &mut R) -> HttpResult<RawStatus> {
622
622
b => match bufwrt. write_u8 ( b) {
623
623
Ok ( _) => ( ) ,
624
624
Err ( _) => {
625
- // what sort of reason phrase is this long?
626
- return Err ( HttpStatusError ) ;
625
+ for _ in range ( 0 u, 128 ) {
626
+ match try!( stream. read_byte ( ) ) {
627
+ CR => match try!( stream. read_byte ( ) ) {
628
+ LF => break ' read,
629
+ _ => return Err ( HttpStatusError )
630
+ } ,
631
+ _ => { /* ignore */ }
632
+ }
633
+ }
634
+ return Err ( HttpStatusError )
627
635
}
628
636
}
629
637
}
@@ -734,9 +742,22 @@ mod tests {
734
742
assert_eq ! ( read_status( & mut mem( s) ) , result) ;
735
743
}
736
744
745
+ fn read_ignore_string ( s : & str , result : HttpResult < RawStatus > ) {
746
+ match ( read_status ( & mut mem ( s) ) , result) {
747
+ ( Ok ( RawStatus ( ref c1, _) ) , Ok ( RawStatus ( ref c2, _) ) ) => {
748
+ assert_eq ! ( c1, c2) ;
749
+ } ,
750
+ ( r1, r2) => assert_eq ! ( r1, r2)
751
+ }
752
+ }
753
+
737
754
read ( "200 OK\r \n " , Ok ( RawStatus ( 200 , Borrowed ( "OK" ) ) ) ) ;
738
755
read ( "404 Not Found\r \n " , Ok ( RawStatus ( 404 , Borrowed ( "Not Found" ) ) ) ) ;
739
756
read ( "200 crazy pants\r \n " , Ok ( RawStatus ( 200 , Owned ( "crazy pants" . to_string ( ) ) ) ) ) ;
757
+ read ( "301 Moved Permanently\r \n " , Ok ( RawStatus ( 301 , Owned ( "Moved Permanently" . to_string ( ) ) ) ) ) ;
758
+ read_ignore_string ( "301 Unreasonably long header that should not happen, \
759
+ but some men just want to watch the world burn\r \n ",
760
+ Ok ( RawStatus ( 301 , Owned ( "Ignored" . to_string ( ) ) ) ) ) ;
740
761
}
741
762
742
763
#[ test]
0 commit comments