|
NAMEHTTP::Parser::XS - a fast, primitive HTTP request parserSYNOPSISuse HTTP::Parser::XS qw(parse_http_request); # for HTTP servers my $ret = parse_http_request( "GET / HTTP/1.0\r\nHost: ...\r\n\r\n", \%env, ); if ($ret == -2) { # request is incomplete ... } elsif ($ret == -1) { # request is broken ... } else { # $ret includes the size of the request, %env now contains a PSGI # request, if it is a POST / PUT request, read request content by # yourself ... } # for HTTP clients use HTTP::Parser::XS qw(parse_http_response HEADERS_AS_ARRAYREF); my %special_headers = ( 'content-length' => undef, ); my($ret, $minor_version, $status, $message, $headers) = parse_http_response($response, HEADERS_AS_ARRAYREF, \%special_headers); if($ret == -1) } # response is incomplete } elsif($ret == -2) { # response is broken } else { # $ret is the length of the headers, starting the content body # the other values are the response messages. For example: # $status = 200 # $message = "OK" # $headers = [ 'content-type' => 'text/html', ... ] # and $special_headers{'content-length'} will be filled in } DESCRIPTIONHTTP::Parser::XS is a fast, primitive HTTP request/response parser.The request parser can be used either for writing a synchronous HTTP server or a event-driven server. The response parser can be used for writing HTTP clients. Note that even if this distribution name ends "::XS", pure Perl implementation is supported, so you can use this module on compiler-less environments. FUNCTIONS
Note that the semantics of PATH_INFO is somewhat different from Apache. First, HTTP::Parser::XS does not validate the variable; it does not raise an error even if PATH_INFO does not start with "/". Second, the variable is conformant to RFC 3875 (and PSGI / Plack) in the fact that "//" and ".." appearing in PATH_INFO are preserved whereas Apache transcodes them.
LIMITATIONSBoth "parse_http_request()" and "parse_http_response()" in XS implementation have some size limitations.The number of headersThe number of headers is limited to 128. If it exceeds, both parsing routines report parsing errors, i.e. return "-1" for $ret.The size of header namesThe size of header names is limited to 1024, but the parsers do not the same action."parse_http_request()" returns "-1" if too-long header names exist. "parse_http_request()" simply ignores too-long header names. COPYRIGHTCopyright 2009- Kazuho OkuAUTHORS
THANKS TO
SEE ALSO
LICENSEThis library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Visit the GSP FreeBSD Man Page Interface. |