http.parsers: parse a "simple request".

db4
John Benediktsson 2015-03-11 17:48:03 -07:00
parent 0fda669750
commit e164fcf431
2 changed files with 32 additions and 3 deletions

View File

@ -46,8 +46,7 @@ IN: http.parsers
{ "0" "1" } one-of ,
] seq* [ "" concat-as ] action ;
PEG: parse-request-line ( string -- triple )
#! Triple is { method url version }
: 'full-request' ( -- parser )
[
'space' ,
'http-method' ,
@ -56,7 +55,20 @@ PEG: parse-request-line ( string -- triple )
'space' ,
'http-version' ,
'space' ,
] seq* just ;
] seq* ;
: 'simple-request' ( -- parser )
[
'space' ,
"GET" token ,
'space' ,
'url' ,
'space' ,
] seq* [ "1.0" suffix! ] action ;
PEG: parse-request-line ( string -- triple )
#! Triple is { method url version }
'full-request' 'simple-request' 2array choice ;
: 'text' ( -- parser )
[ control? ] except ;

View File

@ -63,6 +63,23 @@ IN: http.server.tests
[ read-request ] with-string-reader
] unit-test
! RFC 1945; Section 4.1
! Implement a version of Simple-Request, although rather than
! parse version 0.9, we parse 1.0 to return a Full-Response.
[
T{ request
{ method "GET" }
{ url URL" /" }
{ version "1.0" }
{ header H{ } }
{ cookies V{ } }
{ redirects 10 }
}
] [
"\r\n\r\n\r\nGET /\r\n\r\n"
[ read-request ] with-string-reader
] unit-test
! Don't rethrow parse-errors with an empty request string. They are
! expected from certain browsers when the server serves a certificate
! that the browser can't verify.