HTTP::MessageParser - Parse HTTP Messages
use HTTP::MessageParser; my ( $message, @request ); while ( my $line = $client->getline ) { next if !$message && $line eq "\x0D\x0A"; # RFC 2616 4.1 $message .= $line; last if $message =~ /\x0D\x0A\x0D\x0A$/; } eval { @request = HTTP::MessageParser->parse_request($message); }; if ( $@ ) { # 400 Bad Request } # ...
Parse HTTP/1.0 and HTTP/1.1 Messages.
my @headers = HTTP::MessageParser->parse_headers($string); my $headers = HTTP::MessageParser->parse_headers($string);
Parses Message Headers. field-name's are lowercased. Leading and trailing LWS is removed. LWS occurring between field-content are replaced with a single SP. Takes one argument, a string or a reference to a string, if it's a reference it will be consumed.
Message Headers
field-name
LWS
field-content
SP
my ( $Method, $Request_URI, $HTTP_Version, $Headers, $Body ) = HTTP::MessageParser->parse_request($string);
Parses a Request. Expects a Request-Line followed by zero more header fields and an empty line. Content occurring after end of header fields is returned as a string reference, $Body. Takes one argument, a string or a reference to a string, if it's a reference it will be consumed.
Request-Line
$Body
Throws an exception upon failure.
my ( $Method, $Request_URI, $HTTP_Version ) = HTTP::MessageParser->parse_request_line($string);
Parses a Request-Line. Any leading CRLF is ignored. Takes one argument, a string or a reference to a string, if it's a reference it will be consumed.
CRLF
my ( $HTTP_Version, $Status_Code, $Reason_Phrase, $Headers, $Body ) = HTTP::MessageParser->parse_response($string);
Parses a Response. Expects a Status-Line followed by zero more header fields and an empty line. Content occurring after end of header fields is returned as a string reference, $Body. Takes one argument, a string or a reference to a string, if it's a reference it will be consumed.
Status-Line
my ( $HTTP_Version, $Status_Code, $Reason_Phrase ) = HTTP::MessageParser->parse_response_line($string);
Parses a Status-Line. Takes one argument, a string or a reference to a string, if it's a reference it will be consumed.
my ( $major, $minor ) = HTTP::MessageParser->parse_version($string); my $version = HTTP::MessageParser->parse_version($string);
Parses a HTTP-Version string. In scalar context it returns a version number ( major * 1000 + minor ). In list context it returns major and minor as two separate integers.
HTTP-Version
major * 1000 + minor
major
minor
Nothing by default. Following subroutines can be exported:
http://www.w3.org/Protocols/rfc2616/rfc2616.html
HTTP::Request
HTTP::Response
HTTP::Message
HTTP::Parser
Christian Hansen chansen@cpan.org
chansen@cpan.org
This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
To install HTTP::MessageParser, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTTP::MessageParser
CPAN shell
perl -MCPAN -e shell install HTTP::MessageParser
For more information on module installation, please visit the detailed CPAN module installation guide.