Commit | Line | Data |
aac7ca02 |
1 | NAME |
2 | HTTP::Body - HTTP Body Parser |
3 | |
4 | SYNOPSIS |
5 | use HTTP::Body; |
249dbc12 |
6 | |
7 | sub handler : method { |
09abe57d |
8 | my ( $class, $r ) = @_; |
9 | |
10 | my $content_type = $r->headers_in->get('Content-Type'); |
11 | my $content_length = $r->headers_in->get('Content-Length'); |
249dbc12 |
12 | |
13 | my $body = HTTP::Body->new( $content_type, $content_length ); |
09abe57d |
14 | my $length = $content_length; |
15 | |
16 | while ( $length ) { |
17 | |
18 | $r->read( my $buffer, ( $length < 8192 ) ? $length : 8192 ); |
19 | |
20 | $length -= length($buffer); |
249dbc12 |
21 | |
22 | $body->add($buffer); |
09abe57d |
23 | } |
249dbc12 |
24 | |
25 | my $uploads = $body->upload; # hashref |
09abe57d |
26 | my $params = $body->param; # hashref |
27 | my $body = $body->body; # IO::Handle |
28 | } |
aac7ca02 |
29 | |
30 | DESCRIPTION |
249dbc12 |
31 | HTTP::Body parses chunks of HTTP POST data and supports |
32 | application/octet-stream, application/x-www-form-urlencoded, and |
33 | multipart/form-data. |
34 | |
35 | Chunked bodies are supported by not passing a length value to new(). |
36 | |
37 | It is currently used by Catalyst to parse POST bodies. |
38 | |
39 | NOTES |
40 | When parsing multipart bodies, temporary files are created to store any |
41 | uploaded files. You must delete these temporary files yourself after |
42 | processing them. |
aac7ca02 |
43 | |
44 | METHODS |
09abe57d |
45 | new Constructor. Takes content type and content length as parameters, |
46 | returns a HTTP::Body object. |
47 | |
40a213fd |
48 | add Add string to internal buffer. Will call spin unless done. returns |
09abe57d |
49 | length before adding self. |
50 | |
aac7ca02 |
51 | body |
09abe57d |
52 | accessor for the body. |
53 | |
249dbc12 |
54 | chunked |
55 | Returns 1 if the request is chunked. |
09abe57d |
56 | |
aac7ca02 |
57 | content_length |
249dbc12 |
58 | Returns the content-length for the body data if known. Returns -1 if |
59 | the request is chunked. |
09abe57d |
60 | |
aac7ca02 |
61 | content_type |
249dbc12 |
62 | Returns the content-type of the body data. |
09abe57d |
63 | |
aac7ca02 |
64 | init |
09abe57d |
65 | return self. |
66 | |
aac7ca02 |
67 | length |
249dbc12 |
68 | Returns the total length of data we expect to read if known. In the |
69 | case of a chunked request, returns the amount of data read so far. |
70 | |
71 | trailing_headers |
72 | If a chunked request body had trailing headers, trailing_headers |
73 | will return an HTTP::Headers object populated with those headers. |
09abe57d |
74 | |
aac7ca02 |
75 | spin |
09abe57d |
76 | Abstract method to spin the io handle. |
77 | |
aac7ca02 |
78 | state |
249dbc12 |
79 | Returns the current state of the parser. |
09abe57d |
80 | |
aac7ca02 |
81 | param |
249dbc12 |
82 | Get/set body parameters. |
09abe57d |
83 | |
aac7ca02 |
84 | upload |
249dbc12 |
85 | Get/set file uploads. |
40a213fd |
86 | |
3debb7c0 |
87 | tmpdir |
88 | Specify a different path for temporary files. Defaults to the system |
89 | temporary path. |
90 | |
aac7ca02 |
91 | AUTHOR |
92 | Christian Hansen, "ch@ngmedia.com" |
93 | |
09abe57d |
94 | Sebastian Riedel, "sri@cpan.org" |
95 | |
249dbc12 |
96 | Andy Grundman, "andy@hybridized.org" |
97 | |
aac7ca02 |
98 | LICENSE |
09abe57d |
99 | This library is free software. You can redistribute it and/or modify it |
aac7ca02 |
100 | under the same terms as perl itself. |
101 | |