1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
NAME
POE::Filter::HTTP::Parser - A HTTP POE filter for HTTP clients or
servers
VERSION
version 1.08
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 HTTP which is based on
HTTP::Parser.
It can be used to easily create POE based HTTP servers or clients.
With the type set to client, which is the default behaviour, get will
parse HTTP::Response objects from HTTP streams and put will accept
HTTP::Request objects and convert them to HTTP streams.
With the type set to server, the reverse will happen. get will parse
HTTP::Request objects from HTTP streams and put will accept
HTTP::Response objects and convert them to HTTP streams. Like
POE::Filter::HTTPD if there is an error parsing the HTTP 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
new
Creates a new POE::Filter::HTTP::Parser object. Takes one optional
argument, type which determines whether the filter will act in client
or server mode. client is the default if type is not specified.
'type', set to either 'client' or 'server', default is 'client';
METHODS
get
get_one_start
get_one
Takes an arrayref which contains lines of text. Returns an arrayref
of either HTTP::Request or HTTP::Response objects depending on the
type that has been specified.
get_pending
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.
put
Takes an arrayref of either HTTP::Response objects or HTTP::Request
objects depending on whether type is set to server or client,
respectively.
If type is client, then this accepts HTTP::Request objects. If type
is server, then this accepts HTTP::Response objects.
This does make sense if you think about it.
The given objects are returned to their stream form.
clone
Makes a copy of the filter, and clears the copy's buffer.
CREDITS
The put method for HTTP 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.
SEE ALSO
POE::Filter
HTTP::Parser
POE::Filter::HTTPD
AUTHOR
Chris Williams <chris@bingosnet.co.uk>
COPYRIGHT AND LICENSE
This software is copyright (c) 2016 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.
|