1POE::Filter::HTTPD(3) User Contributed Perl DocumentationPOE::Filter::HTTPD(3)
2
3
4

NAME

6       POE::Filter::HTTPD - convert stream to HTTP::Request; HTTP::Response to
7       stream
8

SYNOPSIS

10         $httpd = POE::Filter::HTTPD->new();
11         $arrayref_with_http_response_as_string =
12           $httpd->put($full_http_response_object);
13         $arrayref_with_http_request_object =
14           $line->get($arrayref_of_raw_data_chunks_from_driver);
15

DESCRIPTION

17       The HTTPD filter parses the first HTTP 1.0 request from an incoming
18       stream into an HTTP::Request object (if the request is good) or an
19       HTTP::Response object (if the request was malformed).  To send a
20       response, give its put() method a HTTP::Response object.
21
22       Here is a sample input handler:
23
24         sub got_request {
25           my ($heap, $request) = @_[HEAP, ARG0];
26
27           # The Filter::HTTPD generated a response instead of a request.
28           # There must have been some kind of error.  You could also check
29           # (ref($request) eq 'HTTP::Response').
30           if ($request->isa('HTTP::Response')) {
31             $heap->{wheel}->put($request);
32             return;
33           }
34
35           # Process the request here.
36           my $response = HTTP::Response->new(200);
37           $response->push_header( 'Content-Type', 'text/html' );
38           $response->content( $request->as_string() );
39
40           $heap->{wheel}->put($response);
41         }
42
43       Please see the documentation for HTTP::Request and HTTP::Response.
44

PUBLIC FILTER METHODS

46       Please see POE::Filter.
47

CAVEATS

49       It is possible to generate invalid HTTP using libwww. This is specifi‐
50       cally a problem if you are talking to a Filter::HTTPD driven daemon
51       using libwww. For example, the following code (taken almost verbatim
52       from the HTTP::Request::Common documentation) will cause an error in a
53       Filter::HTTPD daemon:
54
55         use HTTP::Request::Common;
56         use LWP::UserAgent;
57
58         my $ua = LWP::UserAgent->new();
59         $ua->request(POST 'http://some/poe/driven/site', [ foo => 'bar' ]);
60
61       By default, HTTP::Request is HTTP version agnostic. It makes no attempt
62       to add an HTTP version header unless you specifically declare a proto‐
63       col using "$request->protocol('HTTP/1.0')".
64
65       According to the HTTP 1.0 RFC (1945), when faced with no HTTP version
66       header, the parser is to default to HTTP/0.9. Filter::HTTPD follows
67       this convention. In the transaction detailed above, the Filter::HTTPD
68       based daemon will return a 400 error since POST is not a valid HTTP/0.9
69       request type.
70

Streaming Media

72       It is perfectly possible to use Filter::HTTPD for streaming output
73       media.  Even if it's not possible to change the input filter from Fil‐
74       ter::HTTPD, by setting the output_filter to Filter::Stream and omitting
75       any content in the HTTP::Response object.
76
77         $wheel->put($response); # Without content, it sends just headers.
78         $wheel->set_output_filter(POE::Filter::Stream->new());
79         $wheel->put("Raw content.");
80

SEE ALSO

82       POE::Filter.
83
84       The SEE ALSO section in POE contains a table of contents covering the
85       entire POE distribution.
86

BUGS

88       * Keep-alive is not supported.
89       * The full http 1.0 spec is not supported, specifically DELETE, LINK,
90       and UNLINK.
91

AUTHORS & COPYRIGHTS

93       The HTTPD filter was contributed by Artur Bergman.
94
95       Please see POE for more information about authors and contributors.
96
97
98
99perl v5.8.8                       2006-09-01             POE::Filter::HTTPD(3)
Impressum