From a0f2c4514e969d0a127227201cbdb8e57f71df63 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 5 Jul 2009 15:46:52 -0700 Subject: Rename unicorn/http11 => unicorn_http We couldn't do proper namespacing for the C module so there was a potential conflict with Init_http11() in Mongrel. This was needed because Mongrel's HTTP parser could be used in some applications and we may be unfortunate enough need to support them. --- ext/unicorn_http/unicorn_http_common.rl | 58 +++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 ext/unicorn_http/unicorn_http_common.rl (limited to 'ext/unicorn_http/unicorn_http_common.rl') diff --git a/ext/unicorn_http/unicorn_http_common.rl b/ext/unicorn_http/unicorn_http_common.rl new file mode 100644 index 0000000..61e6d52 --- /dev/null +++ b/ext/unicorn_http/unicorn_http_common.rl @@ -0,0 +1,58 @@ +%%{ + + machine unicorn_http_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 = ( "http"i ("s"i)? ) $downcase_char >mark %scheme; + hostname = (alnum | "-" | "." | "_")+; + host_with_port = (hostname (":" digit*)?) >mark %host; + + 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 ); + path_uri = absolute_path > mark %request_uri; + Absolute_URI = (scheme "://" host_with_port path_uri); + + Request_URI = ((absolute_path | "*") >mark %request_uri) | Absolute_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; + +}%% -- cgit v1.2.3-24-ge0c7