kazuho / p5-http-parser-xs

a fast http parser
30 stars 10 forks source link

Parser depends on SV internals. #18

Open FGasper opened 3 years ago

FGasper commented 3 years ago
> perl -MData::Dumper -MHTTP::Parser::XS -E'my $req = "GET / HTTP/1.0\r\nHost: haha.com\r\nFoo: épée\r\n\r\n"; utf8::upgrade($req); my %env; say HTTP::Parser::XS::parse_http_request($req, \%env); print Dumper \%env;'
51
$VAR1 = {
          'REQUEST_URI' => '/',
          'QUERY_STRING' => '',
          'HTTP_HOST' => 'haha.com',
          'REQUEST_METHOD' => 'GET',
          'SCRIPT_NAME' => '',
          'SERVER_PROTOCOL' => 'HTTP/1.0',
          'PATH_INFO' => '/',
          'HTTP_FOO' => 'épée'
        };

Without the utf8::upgrade it looks as you’d expect:

> perl -MData::Dumper -MHTTP::Parser::XS -E'my $req = "GET / HTTP/1.0\r\nHost: haha.com\r\nFoo: épée\r\n\r\n"; my %env; say HTTP::Parser::XS::parse_http_request($req, \%env); print Dumper \%env;'
47
$VAR1 = {
          'HTTP_HOST' => 'haha.com',
          'HTTP_FOO' => 'épée',
          'QUERY_STRING' => '',
          'REQUEST_URI' => '/',
          'SCRIPT_NAME' => '',
          'SERVER_PROTOCOL' => 'HTTP/1.0',
          'REQUEST_METHOD' => 'GET',
          'PATH_INFO' => '/'
        };