http.server: ignore preceding whitespace before request lines. Fixes #252.

db4
John Benediktsson 2011-10-12 20:21:16 -07:00
parent 1769a63ca3
commit e7fb699832
2 changed files with 26 additions and 1 deletions

View File

@ -29,6 +29,11 @@ IN: http.server.tests
unparse-content-type unparse-content-type
] unit-test ] unit-test
! RFC 2616: Section 19.3
! The line terminator for message-header fields is the sequence CRLF.
! However, we recommend that applications, when parsing such headers,
! recognize a single LF as a line terminator and ignore the leading CR.
[ t ] [ [ t ] [
{ {
"GET / HTTP/1.1" "GET / HTTP/1.1"
@ -38,3 +43,22 @@ IN: http.server.tests
} [ "\n" join ] [ "\r\n" join ] bi } [ "\n" join ] [ "\r\n" join ] bi
[ [ read-request ] with-string-reader ] bi@ = [ [ read-request ] with-string-reader ] bi@ =
] unit-test ] unit-test
! RFC 2616: Section 4.1
! In the interest of robustness, servers SHOULD ignore any empty
! line(s) received where a Request-Line is expected. In other words, if
! the server is reading the protocol stream at the beginning of a
! message and receives a CRLF first, it should ignore the CRLF.
[
T{ request
{ method "GET" }
{ url URL" /" }
{ version "1.0" }
{ header H{ } }
{ cookies V{ } }
{ redirects 10 }
}
] [
"\r\n\r\n\r\nGET / HTTP/1.0\r\n\r\n"
[ read-request ] with-string-reader
] unit-test

View File

@ -37,7 +37,8 @@ IN: http.server
dup path>> "/" head? [ "Bad request: URL" throw ] unless ; inline dup path>> "/" head? [ "Bad request: URL" throw ] unless ; inline
: read-request-line ( request -- request ) : read-request-line ( request -- request )
read-?crlf parse-request-line first3 read-?crlf [ dup empty? ] [ drop read-?crlf ] while
parse-request-line first3
[ >>method ] [ >url check-absolute >>url ] [ >>version ] tri* ; [ >>method ] [ >url check-absolute >>url ] [ >>version ] tri* ;
: read-request-header ( request -- request ) : read-request-header ( request -- request )