Skip to content

Commit

Permalink
http.parsers: parse a "simple request".
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed Mar 12, 2015
1 parent 0fda669 commit e164fcf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
18 changes: 15 additions & 3 deletions basis/http/parsers/parsers.factor
Expand Up @@ -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' ,
Expand All @@ -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 ;
Expand Down
17 changes: 17 additions & 0 deletions basis/http/server/server-tests.factor
Expand Up @@ -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.
Expand Down

0 comments on commit e164fcf

Please sign in to comment.