
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.
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.
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.
Throws an exception upon failure.
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.
Throws an exception upon failure.
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.
Throws an exception upon failure.
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.
Throws an exception upon failure.

Nothing by default. Following subroutines can be exported:

http://www.w3.org/Protocols/rfc2616/rfc2616.html

Christian Hansen chansen@cpan.org

This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.