diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-02-25 12:38:47 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-02-25 12:39:33 -0800 |
commit | d120ffad9716fbb83806d9755b7b5fd28fdb758b (patch) | |
tree | 6c2fde419978edb8d420dbb352c74746626f6fdc /ext/unicorn/http11/http11_parser_common.rl | |
parent | 1f29d32cb095cbc21a095772db2fbaf216781f97 (diff) | |
download | unicorn-d120ffad9716fbb83806d9755b7b5fd28fdb758b.tar.gz |
rename http11 => unicorn/http11
Avoid conflicting with existing (and future) Mongrel installs in case either changes. Of course, this also allows us more freedom to experiment and break the API if needed... However, I'm only planning on making minor changes to remove the amount of C code we have to maintain and possibly some minor performance improvements.
Diffstat (limited to 'ext/unicorn/http11/http11_parser_common.rl')
-rw-r--r-- | ext/unicorn/http11/http11_parser_common.rl | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/ext/unicorn/http11/http11_parser_common.rl b/ext/unicorn/http11/http11_parser_common.rl new file mode 100644 index 0000000..ee970b1 --- /dev/null +++ b/ext/unicorn/http11/http11_parser_common.rl @@ -0,0 +1,55 @@ +%%{ + + machine http_parser_common; + +#### HTTP PROTOCOL GRAMMAR +# line endings + CRLF = "\r\n"; + +# character types + CTL = (cntrl | 127); + safe = ("$" | "-" | "_" | "."); + extra = ("!" | "*" | "'" | "(" | ")" | ","); + reserved = (";" | "/" | "?" | ":" | "@" | "&" | "=" | "+"); + sorta_safe = ("\"" | "<" | ">"); + unsafe = (CTL | " " | "#" | "%" | sorta_safe); + national = any -- (alpha | digit | reserved | extra | safe | unsafe); + unreserved = (alpha | digit | safe | extra | national); + escape = ("%" xdigit xdigit); + uchar = (unreserved | escape | sorta_safe); + pchar = (uchar | ":" | "@" | "&" | "=" | "+"); + tspecials = ("(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\\" | "\"" | "/" | "[" | "]" | "?" | "=" | "{" | "}" | " " | "\t"); + +# elements + token = (ascii -- (CTL | tspecials)); + +# URI schemes and absolute paths + scheme = ( alpha | digit | "+" | "-" | "." )* ; + absolute_uri = (scheme ":" (uchar | reserved )*); + + path = ( pchar+ ( "/" pchar* )* ) ; + query = ( uchar | reserved )* %query_string ; + param = ( pchar | "/" )* ; + params = ( param ( ";" param )* ) ; + rel_path = ( path? %request_path (";" params)? ) ("?" %start_query query)?; + absolute_path = ( "/"+ rel_path ); + + Request_URI = ( "*" | absolute_uri | absolute_path ) >mark %request_uri; + Fragment = ( uchar | reserved )* >mark %fragment; + Method = ( upper | digit | safe ){1,20} >mark %request_method; + + http_number = ( digit+ "." digit+ ) ; + HTTP_Version = ( "HTTP/" http_number ) >mark %http_version ; + Request_Line = ( Method " " Request_URI ("#" Fragment){0,1} " " HTTP_Version CRLF ) ; + + field_name = ( token -- ":" )+ >start_field $snake_upcase_field %write_field; + + field_value = any* >start_value %write_value; + + message_header = field_name ":" " "* field_value :> CRLF; + + Request = Request_Line ( message_header )* ( CRLF @done ); + +main := Request; + +}%% |