Skip to content

Commit 1ed4ea5

Browse files
committed
Merge pull request #164 from dpc/issue-163
Fix Issue 163
2 parents b1761ad + f5a7d7c commit 1ed4ea5

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/http.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,11 +609,11 @@ pub fn read_status<R: Reader>(stream: &mut R) -> HttpResult<RawStatus> {
609609
_ => return Err(HttpStatusError)
610610
}
611611

612-
let mut buf = [b' ', ..16];
612+
let mut buf = [b' ', ..32];
613613

614614
{
615615
let mut bufwrt = BufWriter::new(&mut buf);
616-
loop {
616+
'read: loop {
617617
match try!(stream.read_byte()) {
618618
CR => match try!(stream.read_byte()) {
619619
LF => break,
@@ -622,8 +622,16 @@ pub fn read_status<R: Reader>(stream: &mut R) -> HttpResult<RawStatus> {
622622
b => match bufwrt.write_u8(b) {
623623
Ok(_) => (),
624624
Err(_) => {
625-
// what sort of reason phrase is this long?
626-
return Err(HttpStatusError);
625+
for _ in range(0u, 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)
627635
}
628636
}
629637
}
@@ -734,9 +742,22 @@ mod tests {
734742
assert_eq!(read_status(&mut mem(s)), result);
735743
}
736744

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+
737754
read("200 OK\r\n", Ok(RawStatus(200, Borrowed("OK"))));
738755
read("404 Not Found\r\n", Ok(RawStatus(404, Borrowed("Not Found"))));
739756
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()))));
740761
}
741762

742763
#[test]

0 commit comments

Comments
 (0)