From 18e93c034db0c08bcc5b5f7a72a8fb6e909c009c Mon Sep 17 00:00:00 2001 From: evanweaver Date: Mon, 24 Mar 2008 03:48:10 +0000 Subject: Backport Eric's changes to the http parser from trunk (Eric Wong). Apply fix for Ragel 6 (Eric Wong, Ry Dahl). Two tests fail with the new parser (1 failed with the old parser). Needs investigation. Close #12 (mongrel_rails send_signal leaves a filehandle open until gc). Close #14 (mongrel_rails command line option --num-procs does not change the max number of procs). Close #15 (mongrel squashes helpful exception in register method). Close #16, XXX needs audit! (CGIWrapper "options" attr_reader has no corresponding @options variable). Close #20 (Mongrel doesn't erase temporary files during it's operation on windows). Close #19, XXX needs audit! (HttpResponse#reset does not properly reset HeaderOut). Close #22 (gem_plugin should load gems from Gem.path not Gem.dir). Close #23 (mongrel_cluster's mongrel_rails configuration option isn't fully respected). If I had git, being offline wouldn't have resulted in one massive commit. git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/branches/stable_1-2@995 19e92222-5c0b-0410-8929-a290d50e31e9 --- ext/http11/http11_parser.rl | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'ext/http11/http11_parser.rl') diff --git a/ext/http11/http11_parser.rl b/ext/http11/http11_parser.rl index fffe57a..5e551a3 100644 --- a/ext/http11/http11_parser.rl +++ b/ext/http11/http11_parser.rl @@ -9,6 +9,18 @@ #include #include +/* + * capitalizes all lower-case ASCII characters, + * converts dashes to underscores. + */ +static void snake_upcase_char(char *c) +{ + if (*c >= 'a' && *c <= 'z') + *c &= ~0x20; + else if (*c == '-') + *c = '_'; +} + #define LEN(AT, FPC) (FPC - buffer - parser->AT) #define MARK(M,FPC) (parser->M = (FPC) - buffer) #define PTR_TO(F) (buffer + parser->F) @@ -23,6 +35,7 @@ action start_field { MARK(field_start, fpc); } + action snake_upcase_field { snake_upcase_char((char *)fpc); } action write_field { parser->field_len = LEN(field_start, fpc); } @@ -101,10 +114,9 @@ size_t http_parser_execute(http_parser *parser, const char *buffer, size_t len, p = buffer+off; pe = buffer+len; - assert(*pe == '\0' && "pointer does not end on NUL"); + /* assert(*pe == '\0' && "pointer does not end on NUL"); */ assert(pe - p == len - off && "pointers aren't same distance"); - %% write exec; parser->cs = cs; @@ -117,23 +129,11 @@ size_t http_parser_execute(http_parser *parser, const char *buffer, size_t len, assert(parser->field_len <= len && "field has length longer than whole buffer"); assert(parser->field_start < len && "field starts after buffer end"); - if(parser->body_start) { - /* final \r\n combo encountered so stop right here */ - %%write eof; - parser->nread++; - } - return(parser->nread); } int http_parser_finish(http_parser *parser) { - int cs = parser->cs; - - %%write eof; - - parser->cs = cs; - if (http_parser_has_error(parser) ) { return -1; } else if (http_parser_is_finished(parser) ) { @@ -148,5 +148,5 @@ int http_parser_has_error(http_parser *parser) { } int http_parser_is_finished(http_parser *parser) { - return parser->cs == http_parser_first_final; + return parser->cs >= http_parser_first_final; } -- cgit v1.2.3-24-ge0c7