2007-10-17 03:03:35 -04:00
|
|
|
%%{
|
2019-08-28 13:08:01 -04:00
|
|
|
|
2013-07-18 14:22:18 -04:00
|
|
|
machine puma_parser_common;
|
2007-10-17 03:03:35 -04:00
|
|
|
|
|
|
|
#### HTTP PROTOCOL GRAMMAR
|
|
|
|
# line endings
|
|
|
|
CRLF = "\r\n";
|
|
|
|
|
|
|
|
# character types
|
|
|
|
CTL = (cntrl | 127);
|
|
|
|
safe = ("$" | "-" | "_" | ".");
|
|
|
|
extra = ("!" | "*" | "'" | "(" | ")" | ",");
|
|
|
|
reserved = (";" | "/" | "?" | ":" | "@" | "&" | "=" | "+");
|
|
|
|
unsafe = (CTL | " " | "\"" | "#" | "%" | "<" | ">");
|
|
|
|
national = any -- (alpha | digit | reserved | extra | safe | unsafe);
|
|
|
|
unreserved = (alpha | digit | safe | extra | national);
|
|
|
|
escape = ("%" xdigit xdigit);
|
2016-04-22 20:06:18 -04:00
|
|
|
uchar = (unreserved | escape | "%");
|
2019-08-28 13:08:01 -04:00
|
|
|
pchar = (uchar | ":" | "@" | "&" | "=" | "+" | ";");
|
2007-10-17 03:03:35 -04:00
|
|
|
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 )* ) ;
|
2019-08-28 13:08:01 -04:00
|
|
|
rel_path = ( path? %request_path ) ("?" %start_query query)?;
|
2007-10-17 03:03:35 -04:00
|
|
|
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 ) ;
|
|
|
|
|
2008-03-23 23:48:10 -04:00
|
|
|
field_name = ( token -- ":" )+ >start_field $snake_upcase_field %write_field;
|
2007-10-17 03:03:35 -04:00
|
|
|
|
|
|
|
field_value = any* >start_value %write_value;
|
|
|
|
|
|
|
|
message_header = field_name ":" " "* field_value :> CRLF;
|
|
|
|
|
|
|
|
Request = Request_Line ( message_header )* ( CRLF @done );
|
|
|
|
|
|
|
|
main := Request;
|
2007-10-17 03:10:43 -04:00
|
|
|
|
2007-10-17 03:03:35 -04:00
|
|
|
}%%
|