1HTTP::Body(3) User Contributed Perl Documentation HTTP::Body(3)
2
3
4
6 HTTP::Body - HTTP Body Parser
7
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 $param_order = $body->param_order # arrayref
32 my $body = $body->body; # IO::Handle
33 }
34
36 HTTP::Body parses chunks of HTTP POST data and supports
37 application/octet-stream, application/json,
38 application/x-www-form-urlencoded, and multipart/form-data.
39
40 Chunked bodies are supported by not passing a length value to new().
41
42 It is currently used by Catalyst to parse POST bodies.
43
45 When parsing multipart bodies, temporary files are created to store any
46 uploaded files. You must delete these temporary files yourself after
47 processing them, or set $body->cleanup(1) to automatically delete them
48 at DESTROY-time.
49
51 new Constructor. Takes content type and content length as parameters,
52 returns a HTTP::Body object.
53
54 add Add string to internal buffer. Will call spin unless done. returns
55 length before adding self.
56
57 body
58 accessor for the body.
59
60 chunked
61 Returns 1 if the request is chunked.
62
63 cleanup
64 Set to 1 to enable automatic deletion of temporary files at
65 DESTROY-time.
66
67 content_length
68 Returns the content-length for the body data if known. Returns -1
69 if the request is chunked.
70
71 content_type
72 Returns the content-type of the body data.
73
74 init
75 return self.
76
77 length
78 Returns the total length of data we expect to read if known. In
79 the case of a chunked request, returns the amount of data read so
80 far.
81
82 trailing_headers
83 If a chunked request body had trailing headers, trailing_headers
84 will return an HTTP::Headers object populated with those headers.
85
86 spin
87 Abstract method to spin the io handle.
88
89 state
90 Returns the current state of the parser.
91
92 param
93 Get/set body parameters.
94
95 upload
96 Get/set file uploads.
97
98 part_data
99 Just like 'param' but gives you a hash of the full data associated
100 with the part in a multipart type POST/PUT. Example:
101
102 {
103 data => "test",
104 done => 1,
105 headers => {
106 "Content-Disposition" => "form-data; name=\"arg2\"",
107 "Content-Type" => "text/plain"
108 },
109 name => "arg2",
110 size => 4
111 }
112
113 tmpdir
114 Specify a different path for temporary files. Defaults to the
115 system temporary path.
116
117 param_order
118 Returns the array ref of the param keys in the order how they
119 appeared on the body
120
122 Since its original creation this module has been taken over by the
123 Catalyst development team. If you want to contribute patches, these
124 will be your primary contact points:
125
126 IRC:
127
128 Join #catalyst-dev on irc.perl.org.
129
130 Mailing Lists:
131
132 http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev
133
135 Christian Hansen, "chansen@cpan.org"
136
137 Sebastian Riedel, "sri@cpan.org"
138
139 Andy Grundman, "andy@hybridized.org"
140
142 Simon Elliott "cpan@papercreatures.com"
143
144 Kent Fredric <kentnl@cpan.org>
145
146 Christian Walde
147
148 Torsten Raudssus <torsten@raudssus.de>
149
151 This library is free software. You can redistribute it and/or modify it
152 under the same terms as perl itself.
153
154
155
156perl v5.34.0 2021-07-22 HTTP::Body(3)