6 use List::Util qw[ first ];
9 'application/octet-stream' => 'HTTP::Body::Octetstream',
10 'application/x-www-form-urlencoded' => 'HTTP::Body::Urlencoded',
11 'multipart/form-data' => 'HTTP::Body::Multipart'
15 my ( $class, $content_type, $content_length ) = @_;
18 Carp::croak( $class, '->new( $content_type, $content_length )' );
21 my $type = first { index( lc($content_type), $_ ) >= 0 } keys %{ $PARSERS };
22 my $body = $PARSERS->{ $type || 'application/octet-stream' };
32 content_length => $content_length,
33 content_type => $content_type,
39 bless( $self, $body );
47 if ( defined $_[0] ) {
48 $self->{buffer} .= $_[0];
49 $self->{length} += length($_[0]);
54 return ( $self->length - $self->content_length );
59 $self->{body} = shift if @_;
64 return shift->{buffer};
68 return shift->{content_length};
72 return shift->{content_type};
80 return shift->{length};
84 Carp::croak('Define abstract method spin() in implementation');
92 my ( $name, $value ) = @_;
94 if ( exists $self->{param}->{$name} ) {
95 for ( $self->{param}->{$name} ) {
96 $_ = [$_] unless ref($_) eq "ARRAY";
101 $self->{param}->{$name} = $value;
105 return $self->{param};
113 my ( $name, $upload ) = @_;
115 if ( exists $self->{upload}->{$name} ) {
116 for ( $self->{upload}->{$name} ) {
117 $_ = [$_] unless ref($_) eq "ARRAY";
118 push( @$_, $upload );
122 $self->{upload}->{$name} = $upload;
126 return $self->{upload};