3 machine http_parser_common;
5 #### HTTP PROTOCOL GRAMMAR
11 safe = ("$" | "-" | "_" | ".");
12 extra = ("!" | "*" | "'" | "(" | ")" | ",");
13 reserved = (";" | "/" | "?" | ":" | "@" | "&" | "=" | "+");
14 unsafe = (CTL | " " | "\"" | "#" | "%" | "<" | ">");
15 national = any -- (alpha | digit | reserved | extra | safe | unsafe);
16 unreserved = (alpha | digit | safe | extra | national);
17 escape = ("%" xdigit xdigit);
18 uchar = (unreserved | escape);
19 pchar = (uchar | ":" | "@" | "&" | "=" | "+");
20 tspecials = ("(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\\" | "\"" | "/" | "[" | "]" | "?" | "=" | "{" | "}" | " " | "\t");
23 token = (ascii -- (CTL | tspecials));
25 # URI schemes and absolute paths
26 scheme = ( alpha | digit | "+" | "-" | "." )* ;
27 absolute_uri = (scheme ":" (uchar | reserved )*);
29 path = ( pchar+ ( "/" pchar* )* ) ;
30 query = ( uchar | reserved )* %query_string ;
31 param = ( pchar | "/" )* ;
32 params = ( param ( ";" param )* ) ;
33 rel_path = ( path? %request_path (";" params)? ) ("?" %start_query query)?;
34 absolute_path = ( "/"+ rel_path );
36 Request_URI = ( "*" | absolute_uri | absolute_path ) >mark %request_uri;
37 Fragment = ( uchar | reserved )* >mark %fragment;
38 Method = ( upper | digit | safe ){1,20} >mark %request_method;
40 http_number = ( digit+ "." digit+ ) ;
41 HTTP_Version = ( "HTTP/" http_number ) >mark %http_version ;
42 Request_Line = ( Method " " Request_URI ("#" Fragment){0,1} " " HTTP_Version CRLF ) ;
44 field_name = ( token -- ":" )+ >start_field %write_field;
46 field_value = any* >start_value %write_value;
48 message_header = field_name ":" " "* field_value :> CRLF;
50 Request = Request_Line ( message_header )* ( CRLF @done );