ext/http11/http11_parser.rl in mongrel-1.0.1 vs ext/http11/http11_parser.rl in mongrel-1.0.2

- old
+ new

@@ -11,12 +11,14 @@ #define LEN(AT, FPC) (FPC - buffer - parser->AT) #define MARK(M,FPC) (parser->M = (FPC) - buffer) #define PTR_TO(F) (buffer + parser->F) -/** machine **/ +/** Machine **/ + %%{ + machine http_parser; action mark {MARK(mark, fpc); } @@ -37,10 +39,14 @@ } action request_uri { if(parser->request_uri != NULL) parser->request_uri(parser->data, PTR_TO(mark), LEN(mark, fpc)); } + action fragment { + if(parser->fragment != NULL) + parser->fragment(parser->data, PTR_TO(mark), LEN(mark, fpc)); + } action start_query {MARK(query_start, fpc); } action query_string { if(parser->query_string != NULL) parser->query_string(parser->data, PTR_TO(query_start), LEN(query_start, fpc)); @@ -61,57 +67,11 @@ if(parser->header_done != NULL) parser->header_done(parser->data, fpc + 1, pe - fpc - 1); fbreak; } + include http_parser_common "http11_parser_common.rl"; -#### 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); - uchar = (unreserved | escape); - 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; - 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 " " HTTP_Version CRLF) ; - - field_name = (token -- ":")+ >start_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; }%% /** Data **/ %% write data;