This file documents the revision history for Perl extension HTTP::Body.
+ - 0 length files dont silent disapear, Ash Berlin http://rt.cpan.org/NoAuth/Bug.html?id=25392
+ - YAML is no longer a prereq, tests just wont do anything without it or YAML::Syck
+
0.6 2006-01-06 00:00:00
- Fixed buffer bug in OctetStream, reported by Daisuke Murase <typester@cpan.org>.
- Fixed YAML prereq, reported by Jess Robinson
+++ /dev/null
-Changes
-lib/HTTP/Body.pm
-lib/HTTP/Body/MultiPart.pm
-lib/HTTP/Body/OctetStream.pm
-lib/HTTP/Body/UrlEncoded.pm
-Makefile.PL
-MANIFEST This list of files
-META.yml
-README
-t/01use.t
-t/02pod.t
-t/03podcoverage.t
-t/04multipart.t
-t/05urlencoded.t
-t/06octetstream.t
-t/data/multipart/001-content.dat
-t/data/multipart/001-headers.yml
-t/data/multipart/001-results.yml
-t/data/multipart/002-content.dat
-t/data/multipart/002-headers.yml
-t/data/multipart/002-results.yml
-t/data/multipart/003-content.dat
-t/data/multipart/003-headers.yml
-t/data/multipart/003-results.yml
-t/data/multipart/004-content.dat
-t/data/multipart/004-headers.yml
-t/data/multipart/004-results.yml
-t/data/multipart/005-content.dat
-t/data/multipart/005-headers.yml
-t/data/multipart/005-results.yml
-t/data/multipart/006-content.dat
-t/data/multipart/006-headers.yml
-t/data/multipart/006-results.yml
-t/data/multipart/007-content.dat
-t/data/multipart/007-headers.yml
-t/data/multipart/007-results.yml
-t/data/multipart/008-content.dat
-t/data/multipart/008-headers.yml
-t/data/multipart/008-results.yml
-t/data/multipart/009-content.dat
-t/data/multipart/009-headers.yml
-t/data/multipart/009-results.yml
-t/data/multipart/010-content.dat
-t/data/multipart/010-headers.yml
-t/data/multipart/010-results.yml
-t/data/multipart/011-content.dat
-t/data/multipart/011-headers.yml
-t/data/multipart/011-results.yml
-t/data/octetstream/001-content.dat
-t/data/octetstream/001-headers.yml
-t/data/octetstream/001-results.dat
-t/data/octetstream/002-content.dat
-t/data/octetstream/002-headers.yml
-t/data/octetstream/002-results.dat
-t/data/urlencoded/001-content.dat
-t/data/urlencoded/001-headers.yml
-t/data/urlencoded/001-results.yml
+++ /dev/null
-# http://module-build.sourceforge.net/META-spec.html
-#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
-name: HTTP-Body
-version: 0.4
-version_from: lib/HTTP/Body.pm
-installdirs: site
-requires:
- Carp: 0
- File::Temp: 0.14
- IO::File: 0
- YAML: 0
-
-distribution_type: module
-generated_by: ExtUtils::MakeMaker version 6.17
IO::File => 0,
Params::Validate => 0,
Scalar::Util => 0,
- YAML => '0.39'
}
);
our $VERSION = 0.7;
+=head1 NAME
+
+HTTP::Body - HTTP Body Parser
+
+=head1 SYNOPSIS
+
+ use HTTP::Body;
+
+ sub handler : method {
+ my ( $class, $r ) = @_;
+
+ my $content_type = $r->headers_in->get('Content-Type');
+ my $content_length = $r->headers_in->get('Content-Length');
+
+ 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 $body = $body->body; # IO::Handle
+ }
+
+=head1 DESCRIPTION
+
+HTTP Body Parser.
+
+=head1 METHODS
+
+=over 4
+
+=item new($hashref)
+
+Constructor taking arugments as a hashref. Requires a C<context> argument which
+isa L<HTTP::Body::Context> object, and optional C<bufsize> (integer) and
+C<parser> (L<HTTP::Body::Parser>) arguments.
+
+If called with two arguments C<($content_type, $content_length),
+L<HTTP::Body::Compat> will be used instead to maintain compatability with
+versions <= 0.6
+
+=cut
+
sub new {
my $class = ref $_[0] ? ref shift : shift;
return $self;
}
+=item eos
+
+=cut
+
sub eos {
return shift->parser->eos;
}
+=item put
+
+=cut
+
sub put {
return shift->parser->put(@_);
}
+=back
+
+=head1 AUTHOR
+
+Christian Hansen, C<ch@ngmedia.com>
+
+This pod written by Ash Berlin, C<ash@cpan.org>.
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify
+it under the same terms as perl itself.
+
+=cut
+
1;
use Params::Validate qw[];
use HTTP::Body::Context qw[];
+=head1 NAME
+
+HTTP::Body::Compat - Backwards compataible HTTP Body Parser for versions <= 0.6
+
+=head1 SYNOPSIS
+
+ use HTTP::Body;
+
+ sub handler : method {
+ my ( $class, $r ) = @_;
+
+ my $content_type = $r->headers_in->get('Content-Type');
+ my $content_length = $r->headers_in->get('Content-Length');
+
+ # Calling HTTP::Body->new this way will go into pre 0.7 compat mode
+ 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 $body = $body->body; # IO::Handle
+ }
+
+=head1 DESCRIPTION
+
+HTTP Body Parser.
+
+=head1 METHODS
+
+=over 4
+
+=item new
+
+Constructor. Takes content type and content length as parameters,
+returns a L<HTTP::Body::Compat> object.
+
+=cut
+
sub new {
my $class = ref $_[0] ? ref shift : shift;
my ( $content_type, $content_length ) = Params::Validate::validate_with(
return bless( {}, $class )->initialize( { context => $context } );
}
+=item add
+
+Add string to internal buffer. Returns length before adding string.
+
+=cut
+
sub add {
my $self = shift;
return ( $self->length - $self->content_length );
}
+=item body
+
+accessor for the body
+
+=cut
+
sub body {
return $_[0]->context->content;
}
return '';
}
+=item content_length
+
+Read-only accessor for content legnth
+
+=cut
+
sub content_length {
return $_[0]->context->content_length;
}
+=item content_type
+
+Read-only accessor for content type
+
+=cut
+
sub content_type {
return $_[0]->context->content_type;
}
return 'done';
}
+=item param
+
+Accessor for HTTP parameters
+
+=cut
+
sub param {
my $self = shift;
return scalar $self->context->param->as_hash;
}
+=iteam upload
+
+=cut
+
sub upload {
my $self = shift;
return scalar $self->context->upload->as_hash;
}
+=back
+
+=head1 AUTHOR
+
+Christian Hansen, C<ch@ngmedia.com>
+
+This pod written by Ash Berlin, C<ash@cpan.org>.
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify
+it under the same terms as perl itself.
+
+=cut
+
1;
__PACKAGE__->mk_accessors( qw[ content headers param upload ] );
+=head1 NAME
+
+HTTP::Body::Context
+
+=head1 METHODS
+
+=over
+
+=item new($hashref)
+
+Constructor. Takes the following arguments in a hashref:
+
+=over
+
+=item headers
+
+HTTP::Headers object, or an array or hashref
+
+=item param (optional)
+
+=item upload (optional)
+
+=back
+
+=cut
+
sub new {
my $class = ref $_[0] ? ref shift : shift;
my $params = Params::Validate::validate_with(
return $self;
}
+=item context_length
+
+=cut
+
sub content_length {
return shift->headers->content_length(@_);
}
+=item content_type
+
+=cut
+
sub content_type {
return shift->headers->content_type(@_);
}
+=item header
+
+=cut
+
sub header {
return shift->headers->header(@_);
}
+=back
+
+=head1 AUTHOR
+
+Christian Hansen, C<ch@ngmedia.com>
+
+This pod written by Ash Berlin, C<ash@cpan.org>.
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify
+it under the same terms as perl itself.
+
+=cut
+
1;
__END__
__PACKAGE__->register_parser( 'application/x-www-form-urlencoded' => 'HTTP::Body::Parser::UrlEncoded' );
__PACKAGE__->register_parser( 'multipart/form-data' => 'HTTP::Body::Parser::MultiPart' );
+=head1 NAME
+
+HTTP::Body::Parser
+
+=head1 METHODS
+
+=over 4
+
+=item new($hashref)
+
+Constructor.
+
+=cut
+
sub new {
my $class = ref $_[0] ? ref shift : shift;
my $params = Params::Validate::validate_with(
return $self->parse;
}
+=back
+
+=head1 AUTHOR
+
+Christian Hansen, C<ch@ngmedia.com>
+
+This pod written by Ash Berlin, C<ash@cpan.org>.
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify
+it under the same terms as perl itself.
+
+=cut
+
1;
use strict;
use warnings;
-use Test::More tests => 55;
+use Test::More;
+
+eval { require YAML; import YAML 'LoadFile'; };
+if ($@) {
+ eval { require YAML::Syck; import YAML::Syck 'LoadFile'; }
+}
+
+plan skip_all => 'Tests need YAML or YAML::Syck' if $@;
+
+plan tests => 55;
use Cwd;
use HTTP::Body;
use File::Spec::Functions;
use IO::File;
-use YAML;
my $path = catdir( getcwd(), 't', 'data', 'multipart' );
for ( my $i = 1; $i <= 11; $i++ ) {
my $test = sprintf( "%.3d", $i );
- my $headers = YAML::LoadFile( catfile( $path, "$test-headers.yml" ) );
- my $results = YAML::LoadFile( catfile( $path, "$test-results.yml" ) );
+ my $headers = LoadFile( catfile( $path, "$test-headers.yml" ) );
+ my $results = LoadFile( catfile( $path, "$test-results.yml" ) );
my $content = IO::File->new( catfile( $path, "$test-content.dat" ) );
my $body = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
use strict;
use warnings;
-use Test::More tests => 5;
+use Test::More
+
+eval { require YAML; import YAML 'LoadFile'; };
+if ($@) {
+ eval { require YAML::Syck; import YAML::Syck 'LoadFile'; }
+}
+
+plan skip_all => 'Tests need YAML or YAML::Syck' if $@;
+
+plan tests => 5;
use Cwd;
use HTTP::Body;
use File::Spec::Functions;
use IO::File;
-use YAML;
my $path = catdir( getcwd(), 't', 'data', 'urlencoded' );
use strict;
use warnings;
-use Test::More tests => 8;
+use Test::More;
+
+eval { require YAML; import YAML 'LoadFile'; };
+if ($@) {
+ eval { require YAML::Syck; import YAML::Syck 'LoadFile'; }
+}
+
+plan skip_all => 'Tests need YAML or YAML::Syck' if $@;
+
+plan tests => 8;
use Cwd;
use HTTP::Body;
use File::Spec::Functions;
use IO::File;
-use YAML;
my $path = catdir( getcwd(), 't', 'data', 'octetstream' );