NAME

HTTP::StreamParser - support for streaming HTTP request/response parsing

VERSION

version 0.101

SYNOPSIS

# 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

DESCRIPTION

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".

new

Instantiates a new parser object.

parse

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.

parse_state

Sets the current parse state, then calls the state handler.

next_state

Moves to the next parser state.

handle_state

Call the handler for our current parser state.

validate_method

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

http_method

Parses the HTTP method information.

validate_code

Validate whether we have a sensible HTTP status code - currently, any code >= 100 is accepted.

http_code

Parse an HTTP status code.

http_status

Parse the HTTP status information - this is everything after the code to the end of the line.

http_uri

Parse URI information. Anything up to whitespace.

http_version

Parse HTTP version information. Typically expects HTTP/1.1.

http_headers

Parse HTTP header lines.

single_space

Parse a single space character.

Returns $self.

newline

Parse the "newline" (CRLF) characters.

Returns $self.

http_body

Parse body chunks.

Returns $self.

SEE ALSO

AUTHOR

Tom Molesworth <cpan@entitymodel.com>

LICENSE

Copyright Tom Molesworth 2013. Licensed under the same terms as Perl itself.