http.server: ignore preceding whitespace before request lines. Fixes #252.
parent
1769a63ca3
commit
e7fb699832
|
@ -29,6 +29,11 @@ IN: http.server.tests
|
|||
unparse-content-type
|
||||
] 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 ] [
|
||||
{
|
||||
"GET / HTTP/1.1"
|
||||
|
@ -38,3 +43,22 @@ IN: http.server.tests
|
|||
} [ "\n" join ] [ "\r\n" join ] bi
|
||||
[ [ read-request ] with-string-reader ] bi@ =
|
||||
] 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
|
||||
|
|
|
@ -37,7 +37,8 @@ IN: http.server
|
|||
dup path>> "/" head? [ "Bad request: URL" throw ] unless ; inline
|
||||
|
||||
: 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* ;
|
||||
|
||||
: read-request-header ( request -- request )
|
||||
|
|
Loading…
Reference in New Issue