HTTP::StreamParser - support for streaming HTTP request/response parsing
version 0.101
# For requests... my $req_parser = HTTP::StreamParser::Request->new; $req_parser->subscribe_to_event( http_method => sub { print "Method: $_[1]\n" }, http_uri => sub { print "URI: $_[1]\n" }, http_header => sub { print "Header: $_[1]: $_[2]\n" }, ); $req_parser->parse(<<'EOF'); ... EOF # ... and responses: my $resp_parser = HTTP::StreamParser::Request->new; $resp_parser->subscribe_to_event( http_code => sub { print "Code: $_[1]\n" }, http_status => sub { print "Status: $_[1]\n" }, http_header => sub { print "Header: $_[1]: $_[2]\n" }, ); $resp_parser->parse(<<'EOF'); ... EOF
Parses HTTP requests or responses. Generates events. Should be suitable for streaming. You may be looking for HTTP::Parser::XS instead - it's at least 20x faster than this module. If you wanted something without XS, there's HTTP::Parser.
Actual implementation is in HTTP::StreamParser::Request or HTTP::StreamParser::Response.
Typically you'd instantiate one of these for each request you want to parse. You'd then subscribe to the events you're interested in - for example, header information, request method, etc. - and then start parsing via "parse".
Instantiates a new parser object.
Adds the given data to the pending buffer, and calls the state handler to check whether we have enough data to do some useful parsing.
Sets the current parse state, then calls the state handler.
Moves to the next parser state.
Call the handler for our current parser state.
Validate the HTTP request method. Currently accepts any of these:
CONNECT
COPY
DELETE
DELTA
FILEPATCH
GET
HEAD
LOCK
MKCOL
MOVE
OPTIONS
PATCH
POST
PROPFIND
PROPPATCH
PUT
SIGNATURE
TRACE
TRACK
UNLOCK
Parses the HTTP method information.
Validate whether we have a sensible HTTP status code - currently, any code >= 100 is accepted.
Parse an HTTP status code.
Parse the HTTP status information - this is everything after the code to the end of the line.
Parse URI information. Anything up to whitespace.
Parse HTTP version information. Typically expects HTTP/1.1.
Parse HTTP header lines.
Parse a single space character.
Returns $self.
Parse the "newline" (CRLF) characters.
Parse body chunks.
HTTP::Parser::XS - used by several other modules, fast implementation, pure-Perl fallback, but doesn't give access to the data until the headers have been parsed and aside from header count and per-header size limitation, seems not to have any way to deal with oversized requests
HTTP::Parser - parses into HTTP::Request/HTTP::Response objects. Doesn't seem to guard against large buffers but does have at least some support for streaming.
HTTP::MessageParser - also parses HTTP content
Mojo::Message::Request - part of Mojolicious
Mojo::Message::Response - part of Mojolicious
HTTP::Response::Parser - parses responses...
POE::Filter::HTTP::Parser - seems to be backed by HTTP::Parser::XS / HTTP::Parser
HTTP::HeaderParser::XS - only parses the headers, albeit with some speed
Tom Molesworth <cpan@entitymodel.com>
Copyright Tom Molesworth 2013. Licensed under the same terms as Perl itself.
To install HTTP::StreamParser, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTTP::StreamParser
CPAN shell
perl -MCPAN -e shell install HTTP::StreamParser
For more information on module installation, please visit the detailed CPAN module installation guide.