.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "HTTP::Body 3pm" .TH HTTP::Body 3pm "2022-06-14" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" HTTP::Body \- HTTP Body Parser .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use HTTP::Body; \& \& sub handler : method { \& my ( $class, $r ) = @_; \& \& my $content_type = $r\->headers_in\->get(\*(AqContent\-Type\*(Aq); \& my $content_length = $r\->headers_in\->get(\*(AqContent\-Length\*(Aq); \& \& my $body = HTTP::Body\->new( $content_type, $content_length ); \& my $length = $content_length; \& \& while ( $length ) { \& \& $r\->read( my $buffer, ( $length < 8192 ) ? $length : 8192 ); \& \& $length \-= length($buffer); \& \& $body\->add($buffer); \& } \& \& my $uploads = $body\->upload; # hashref \& my $params = $body\->param; # hashref \& my $param_order = $body\->param_order # arrayref \& my $body = $body\->body; # IO::Handle \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" HTTP::Body parses chunks of \s-1HTTP POST\s0 data and supports application/octet\-stream, application/json, application/x\-www\-form\-urlencoded, and multipart/form\-data. .PP Chunked bodies are supported by not passing a length value to \fBnew()\fR. .PP It is currently used by Catalyst to parse \s-1POST\s0 bodies. .SH "NOTES" .IX Header "NOTES" When parsing multipart bodies, temporary files are created to store any uploaded files. You must delete these temporary files yourself after processing them, or set \f(CW$body\fR\->\fBcleanup\fR\|(1) to automatically delete them at DESTROY-time. .SH "METHODS" .IX Header "METHODS" .IP "new" 4 .IX Item "new" Constructor. Takes content type and content length as parameters, returns a HTTP::Body object. .IP "add" 4 .IX Item "add" Add string to internal buffer. Will call spin unless done. returns length before adding self. .IP "body" 4 .IX Item "body" accessor for the body. .IP "chunked" 4 .IX Item "chunked" Returns 1 if the request is chunked. .IP "cleanup" 4 .IX Item "cleanup" Set to 1 to enable automatic deletion of temporary files at DESTROY-time. .IP "content_length" 4 .IX Item "content_length" Returns the content-length for the body data if known. Returns \-1 if the request is chunked. .IP "content_type" 4 .IX Item "content_type" Returns the content-type of the body data. .IP "init" 4 .IX Item "init" return self. .IP "length" 4 .IX Item "length" Returns the total length of data we expect to read if known. In the case of a chunked request, returns the amount of data read so far. .IP "trailing_headers" 4 .IX Item "trailing_headers" If a chunked request body had trailing headers, trailing_headers will return an HTTP::Headers object populated with those headers. .IP "spin" 4 .IX Item "spin" Abstract method to spin the io handle. .IP "state" 4 .IX Item "state" Returns the current state of the parser. .IP "param" 4 .IX Item "param" Get/set body parameters. .IP "upload" 4 .IX Item "upload" Get/set file uploads. .IP "part_data" 4 .IX Item "part_data" Just like 'param' but gives you a hash of the full data associated with the part in a multipart type \s-1POST/PUT.\s0 Example: .Sp .Vb 10 \& { \& data => "test", \& done => 1, \& headers => { \& "Content\-Disposition" => "form\-data; name=\e"arg2\e"", \& "Content\-Type" => "text/plain" \& }, \& name => "arg2", \& size => 4 \& } .Ve .IP "tmpdir" 4 .IX Item "tmpdir" Specify a different path for temporary files. Defaults to the system temporary path. .IP "param_order" 4 .IX Item "param_order" Returns the array ref of the param keys in the order how they appeared on the body .SH "SUPPORT" .IX Header "SUPPORT" Since its original creation this module has been taken over by the Catalyst development team. If you want to contribute patches, these will be your primary contact points: .PP \&\s-1IRC:\s0 .PP .Vb 1 \& Join #catalyst\-dev on irc.perl.org. .Ve .PP Mailing Lists: .PP .Vb 1 \& http://lists.scsys.co.uk/cgi\-bin/mailman/listinfo/catalyst\-dev .Ve .SH "AUTHOR" .IX Header "AUTHOR" Christian Hansen, \f(CW\*(C`chansen@cpan.org\*(C'\fR .PP Sebastian Riedel, \f(CW\*(C`sri@cpan.org\*(C'\fR .PP Andy Grundman, \f(CW\*(C`andy@hybridized.org\*(C'\fR .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" Simon Elliott \f(CW\*(C`cpan@papercreatures.com\*(C'\fR .PP Kent Fredric .PP Christian Walde .PP Torsten Raudssus .SH "LICENSE" .IX Header "LICENSE" This library is free software. You can redistribute it and/or modify it under the same terms as perl itself.