1HTTP::Body(3)         User Contributed Perl Documentation        HTTP::Body(3)
2
3
4

NAME

6       HTTP::Body - HTTP Body Parser
7

SYNOPSIS

9           use HTTP::Body;
10
11           sub handler : method {
12               my ( $class, $r ) = @_;
13
14               my $content_type   = $r->headers_in->get('Content-Type');
15               my $content_length = $r->headers_in->get('Content-Length');
16
17               my $body   = HTTP::Body->new( $content_type, $content_length );
18               my $length = $content_length;
19
20               while ( $length ) {
21
22                   $r->read( my $buffer, ( $length < 8192 ) ? $length : 8192 );
23
24                   $length -= length($buffer);
25
26                   $body->add($buffer);
27               }
28
29               my $uploads = $body->upload; # hashref
30               my $params  = $body->param;  # hashref
31               my $body    = $body->body;   # IO::Handle
32           }
33

DESCRIPTION

35       HTTP::Body parses chunks of HTTP POST data and supports
36       application/octet-stream, application/x-www-form-urlencoded, and
37       multipart/form-data.
38
39       Chunked bodies are supported by not passing a length value to new().
40
41       It is currently used by Catalyst to parse POST bodies.
42

NOTES

44       When parsing multipart bodies, temporary files are created to store any
45       uploaded files.  You must delete these temporary files yourself after
46       processing them, or set $body->cleanup(1) to automatically delete them
47       at DESTROY-time.
48

METHODS

50       new Constructor. Takes content type and content length as parameters,
51           returns a HTTP::Body object.
52
53       add Add string to internal buffer. Will call spin unless done. returns
54           length before adding self.
55
56       body
57           accessor for the body.
58
59       chunked
60           Returns 1 if the request is chunked.
61
62       cleanup
63           Set to 1 to enable automatic deletion of temporary files at
64           DESTROY-time.
65
66       content_length
67           Returns the content-length for the body data if known.  Returns -1
68           if the request is chunked.
69
70       content_type
71           Returns the content-type of the body data.
72
73       init
74           return self.
75
76       length
77           Returns the total length of data we expect to read if known.  In
78           the case of a chunked request, returns the amount of data read so
79           far.
80
81       trailing_headers
82           If a chunked request body had trailing headers, trailing_headers
83           will return an HTTP::Headers object populated with those headers.
84
85       spin
86           Abstract method to spin the io handle.
87
88       state
89           Returns the current state of the parser.
90
91       param
92           Get/set body parameters.
93
94       upload
95           Get/set file uploads.
96
97       tmpdir
98           Specify a different path for temporary files.  Defaults to the
99           system temporary path.
100

AUTHOR

102       Christian Hansen, "chansen@cpan.org"
103
104       Sebastian Riedel, "sri@cpan.org"
105
106       Andy Grundman, "andy@hybridized.org"
107

LICENSE

109       This library is free software. You can redistribute it and/or modify it
110       under the same terms as perl itself.
111
112
113
114perl v5.12.0                      2010-01-24                     HTTP::Body(3)
Impressum