The temp file name now preserves the uploaded file's suffix.
[catagits/HTTP-Body.git] / README
1 NAME
2     HTTP::Body - HTTP Body Parser
3
4 SYNOPSIS
5         use HTTP::Body;
6         
7     sub handler : method {
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');
12             
13         my $body   = HTTP::Body->new( $content_type, $content_length );
14             my $length = $content_length;
15
16             while ( $length ) {
17
18                 $r->read( my $buffer, ( $length < 8192 ) ? $length : 8192 );
19
20                 $length -= length($buffer);
21                 
22             $body->add($buffer);
23             }
24             
25         my $uploads = $body->upload; # hashref
26             my $params  = $body->param;  # hashref
27             my $body    = $body->body;   # IO::Handle
28         }
29
30 DESCRIPTION
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.
43
44 METHODS
45     new Constructor. Takes content type and content length as parameters,
46         returns a HTTP::Body object.
47
48     add Add string to internal buffer. Will call spin unless done. returns
49         length before adding self.
50
51     body
52         accessor for the body.
53
54     chunked
55         Returns 1 if the request is chunked.
56
57     content_length
58         Returns the content-length for the body data if known. Returns -1 if
59         the request is chunked.
60
61     content_type
62         Returns the content-type of the body data.
63
64     init
65         return self.
66
67     length
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.
74
75     spin
76         Abstract method to spin the io handle.
77
78     state
79         Returns the current state of the parser.
80
81     param
82         Get/set body parameters.
83
84     upload
85         Get/set file uploads.
86
87     tmpdir
88         Specify a different path for temporary files. Defaults to the system
89         temporary path.
90
91 AUTHOR
92     Christian Hansen, "ch@ngmedia.com"
93
94     Sebastian Riedel, "sri@cpan.org"
95
96     Andy Grundman, "andy@hybridized.org"
97
98 LICENSE
99     This library is free software. You can redistribute it and/or modify it
100     under the same terms as perl itself.
101