VERSION

version 1.06

SYNOPSIS

    use POE::Filter::HTTP::Parser;

    # For HTTP Servers

    my $request_filter = POE::Filter::HTTP::Parser->new( type => 'server' );
    my $arrayref_of_request_objects = $filter->get( [ $stream ] );

    my $arrayref_of_HTTP_stream = $filter->put( $arrayref_of_response_objects );

    # For HTTP clients

    my $response_filter = POE::Filter::HTTP::Parser->new( type => 'client' );
    my $arrayref_of_HTTP_stream = $filter->put( $arrayref_of_request_objects );

    my $arrayref_of_response_objects = $filter->get( [ $stream ] );

DESCRIPTION

POE::Filter::HTTP::Parser is a POE::Filter for \s-1HTTP\s0 which is based on HTTP::Parser.

It can be used to easily create \s-1POE\s0 based \s-1HTTP\s0 servers or clients.

With the \*(C`type\*(C' set to \*(C`client\*(C', which is the default behaviour, \*(C`get\*(C' will parse HTTP::Response objects from \s-1HTTP\s0 streams and \*(C`put\*(C' will accept HTTP::Request objects and convert them to \s-1HTTP\s0 streams.

With the \*(C`type\*(C' set to \*(C`server\*(C', the reverse will happen. \*(C`get\*(C' will parse HTTP::Request objects from \s-1HTTP\s0 streams and \*(C`put\*(C' will accept HTTP::Response objects and convert them to \s-1HTTP\s0 streams. Like POE::Filter::HTTPD if there is an error parsing the \s-1HTTP\s0 request, this filter will generate a HTTP::Response object instead, to encapsulate the error message, suitable for simply sending back to the requesting client.

CONSTRUCTOR

Creates a new POE::Filter::HTTP::Parser object. Takes one optional argument, \*(C`type\*(C' which determines whether the filter will act in \*(C`client\*(C' or \*(C`server\*(C' mode. \*(C`client\*(C' is the default if \*(C`type\*(C' is not specified. 'type', set to either 'client' or 'server', default is 'client';

METHODS

Takes an arrayref which contains lines of text. Returns an arrayref of either HTTP::Request or HTTP::Response objects depending on the \*(C`type\*(C' that has been specified. Returns any data remaining in a filter's input buffer. The filter's input buffer is not cleared, however. Returns an array reference if there's any data, or undef if the filter was empty. Takes an arrayref of either HTTP::Response objects or HTTP::Request objects depending on whether \*(C`type\*(C' is set to \*(C`server\*(C' or \*(C`client\*(C', respectively. If \*(C`type\*(C' is \*(C`client\*(C', then this accepts HTTP::Request objects. If \*(C`type\*(C' is \*(C`server\*(C', then this accepts HTTP::Response objects. This does make sense if you think about it. The given objects are returned to their stream form. Makes a copy of the filter, and clears the copy's buffer.

CREDITS

The \*(C`put\*(C' method for \s-1HTTP\s0 responses was borrowed from POE::Filter::HTTPD, along with the code to generate HTTP::Response on a parse error, by Artur Bergman and Rocco Caputo.

RELATED TO POE::Filter::HTTP::Parser…

POE::Filter

HTTP::Parser

POE::Filter::HTTPD

AUTHOR

Chris Williams <[email protected]>

COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Chris Williams, Artur Bergman and Rocco Caputo.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.