HTTP-Request-Params-1.02/0000755000310400017500000000000012562346150013207 5ustar kizianHTTP-Request-Params-1.02/t/0000755000310400017500000000000012562346150013452 5ustar kizianHTTP-Request-Params-1.02/t/test.t0000644000310400017500000000346412556155653014636 0ustar kizian#!/usr/bin/perl use Test::More qw[no_plan]; use strict; $^W = 1; BEGIN { require_ok 'CGI'; require_ok 'Email::MIME'; require_ok 'Email::MIME::Modifier'; require_ok 'Email::MIME::ContentType'; require_ok 'HTTP::Request'; require_ok 'HTTP::Message'; require_ok 'Class::Accessor::Fast'; use_ok 'HTTP::Request::Params'; use_ok 'HTTP::Request::Common'; use_ok 'HTTP::Request'; } my $get_request = HTTP::Request::Params->new({ req => get_request(), }); test_request($get_request); my $post_request = HTTP::Request::Params->new({req => post_request()}); test_request($post_request); my $post_upload_request = HTTP::Request::Params->new({req => post_upload_request()}); test_request($post_upload_request); like $post_upload_request->params->{myself}, qr/sub post_upload_request/, 'found myself'; is scalar($post_upload_request->mime->parts), 3; sub test_request { isa_ok $get_request, 'HTTP::Request::Params'; isa_ok $get_request->req, 'HTTP::Request'; isa_ok $get_request->mime, 'Email::MIME'; is ref($get_request->params), 'HASH', 'params is HASH'; is ref($get_request->params->{multi}), 'ARRAY', 'params->{multi} is ARRAY'; ok !ref($get_request->params->{single}), 'params->{single} is singular'; is $get_request->params->{single}, 'one', 'single is one'; } sub get_request { HTTP::Request->new(GET => q[http://example.com/?multi=1;multi=2;single=one]); } sub post_request { <<__REQ__; POST http://example.com?multi=1 multi=2;single=one __REQ__ } sub post_upload_request { my $req = POST q[http://exmaple.com/?multi=2], Content_Type => 'form-data', Content => [ multi => 1, single => 'one', myself => [ $0 ], ]; return $req; } HTTP-Request-Params-1.02/MANIFEST0000644000310400017500000000027212562346150014341 0ustar kizianChanges lib/HTTP/Request/Params.pm Makefile.PL MANIFEST This list of files META.yml README t/test.t META.json Module JSON meta-data (added by MakeMaker) HTTP-Request-Params-1.02/lib/0000755000310400017500000000000012562346150013755 5ustar kizianHTTP-Request-Params-1.02/lib/HTTP/0000755000310400017500000000000012562346150014534 5ustar kizianHTTP-Request-Params-1.02/lib/HTTP/Request/0000755000310400017500000000000012562346150016164 5ustar kizianHTTP-Request-Params-1.02/lib/HTTP/Request/Params.pm0000644000310400017500000001100212562325453017742 0ustar kizianpackage HTTP::Request::Params; # $Id: Params.pm,v 1.2 2015/08/11 10:01:12 kiz Exp $ use strict; =pod =head1 NAME HTTP::Request::Params - Retrieve GET/POST Parameters from HTTP Requests =head1 SYNOPSIS use HTTP::Request::Params; my $http_request = read_request(); my $parse_params = HTTP::Request::Params->new({ req => $http_request, }); my $params = $parse_params->params; =cut use vars qw[$VERSION]; $VERSION = sprintf '%d.%02d', split m/\./, (qw$Revision: 1.2 $)[1]; use CGI; use Email::MIME; use Email::MIME::Modifier; use Email::MIME::ContentType qw[parse_content_type]; use HTTP::Request; use HTTP::Message; use parent qw[Class::Accessor::Fast]; =pod =head1 DESCRIPTION This software does all the dirty work of parsing HTTP Requests to find incoming query parameters. =head2 new my $parser = HTTP::Request::Params->new({ req => $http_request, }); C - This required argument is either an C object or a string containing an entier HTTP Request. Incoming query parameters come from two places. The first place is the C portion of the URL. Second is the content portion of an HTTP request as is the case when parsing a POST request, for example. =head2 params my $params = $parser->params; Returns a hash reference containing all the parameters. The keys in this hash are the names of the parameters. Values are the values associated with those parameters in the incoming query. For parameters with multiple values, the value in this hash will be a list reference. This is the same behaviour as the C module's C function. =head2 req my $req_object = $parser->req; Returns the C object. =head2 mime my $mime_object = $parser->mime; Returns the C object. Now, you may be wondering why we're dealing with an C object. The answer is simple. It's an amazing parser for MIME compliant messages, and RFC 822 compliant messages. When parsing incoming POST data, especially file uploads, C is the perfect fit. It's fast and light. =cut sub new { my ($class) = shift; my $self = $class->SUPER::new(@_); if ( not ref( $self->req ) ) { $self->req( HTTP::Request->parse( $self->req ) ); } my $message = ( split /\n/, $self->req->as_string, 2 )[1]; $self->mime( Email::MIME->new( $self->req->as_string ) ); $self->_find_params; return $self; } ## end sub new __PACKAGE__->mk_accessors(qw[req mime params]); sub _find_params { my $self = shift; my $query_params = CGI->new( $self->req->url->query )->Vars; my $post_params = {}; if ( $self->mime->parts > 1 ) { foreach my $part ( $self->mime->parts ) { next if $part == $self->mime; $part->disposition_set('text/plain'); # for easy parsing my $disp = $part->header('Content-Disposition'); my $ct = parse_content_type($disp); my $name = $ct->{attributes}->{name}; my $content = $part->body; $content =~ s/\r\n$//; $self->_add_to_field( $post_params, $name, $content ); } ## end foreach my $part ( $self->mime...) } else { my $body = $self->mime->body; chomp $body; $post_params = CGI->new($body)->Vars; } my $params = {}; # I dislike the use of $_ for my $k ( keys %{$post_params} ) { $self->_add_to_field( $params, $k, $post_params->{$k} ); } for my $k ( keys %{$query_params} ) { $self->_add_to_field( $params, $k, $query_params->{$k} ); } $self->params($params); return keys %{$params} ? 0 : 1; } ## end sub _find_params sub _add_to_field { my ( $self, $hash, $name, @content ) = @_; my $field = $hash->{$name}; if ( @content && ref( $content[0] ) ) { @content = @{ $content[0] }; } @content = map split(/\0/), @content; if ( defined $field ) { if ( ref($field) ) { push @{$field}, @content; } else { $field = [ $field, @content ]; } } else { if ( @content > 1 ) { $field = \@content; } else { $field = $content[0]; } } ## end else [ if ( defined $field ) ] $hash->{$name} = $field; return $field ? 1 : 0; } ## end sub _add_to_field 1; __END__ =head1 SEE ALSO C, L, L, L, L. =head1 AUTHOR Casey West, >. Ian Stuart, >. =head1 COPYRIGHT Copyright (c) 2015 Casey West. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut HTTP-Request-Params-1.02/META.json0000644000310400017500000000220212562346150014624 0ustar kizian{ "abstract" : "Retrieve GET/POST Parameters from HTTP Requests", "author" : [ "Casey West ", "Ian Stuart " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.66, CPAN::Meta::Converter version 2.133380", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "HTTP-Request-Params", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "CGI" : "3.00", "Class::Accessor::Fast" : "0.19", "Email::MIME" : "1.42", "Email::MIME::ContentType" : "1.0", "HTTP::Request" : "1.40", "HTTP::Request::Common" : "1.26" } } }, "release_status" : "stable", "version" : "1.02" } HTTP-Request-Params-1.02/Changes0000644000310400017500000000020512562317250014476 0ustar kizian2015-08-11 1.02 - Update to clear an upstream bug created by changes to Email::MIME 2004-05-11 1.01 - Initial revision. HTTP-Request-Params-1.02/META.yml0000644000310400017500000000125512562346150014463 0ustar kizian--- abstract: 'Retrieve GET/POST Parameters from HTTP Requests' author: - 'Casey West ' - 'Ian Stuart ' build_requires: ExtUtils::MakeMaker: 0 configure_requires: ExtUtils::MakeMaker: 0 dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.66, CPAN::Meta::Converter version 2.133380' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: HTTP-Request-Params no_index: directory: - t - inc requires: CGI: 3.00 Class::Accessor::Fast: 0.19 Email::MIME: 1.42 Email::MIME::ContentType: 1.0 HTTP::Request: 1.40 HTTP::Request::Common: 1.26 version: 1.02 HTTP-Request-Params-1.02/Makefile.PL0000644000310400017500000000145112562324100015151 0ustar kizianuse ExtUtils::MakeMaker; WriteMakefile ( AUTHOR => ['Casey West ', 'Ian Stuart '], ABSTRACT => "Retrieve GET/POST Parameters from HTTP Requests", NAME => 'HTTP::Request::Params', PREREQ_PM => { 'CGI' => '3.00', 'Class::Accessor::Fast' => '0.19', 'Email::MIME::ContentType' => '1.0', 'Email::MIME' => '1.42', 'HTTP::Request' => '1.40', 'HTTP::Request::Common' => '1.26', }, VERSION_FROM => 'lib/HTTP/Request/Params.pm', ); HTTP-Request-Params-1.02/README0000644000310400017500000000412312562346010014062 0ustar kizianNAME HTTP::Request::Params - Retrieve GET/POST Parameters from HTTP Requests SYNOPSIS use HTTP::Request::Params; my $http_request = read_request(); my $parse_params = HTTP::Request::Params->new({ req => $http_request, }); my $params = $parse_params->params; DESCRIPTION This software does all the dirty work of parsing HTTP Requests to find incoming query parameters. new my $parser = HTTP::Request::Params->new({ req => $http_request, }); "req" - This required argument is either an "HTTP::Request" object or a string containing an entire HTTP Request. Incoming query parameters come from two places. The first place is the "query" portion of the URL. Second is the content portion of an HTTP request as is the case when parsing a POST request, for example. params my $params = $parser->params; Returns a hash reference containing all the parameters. The keys in this hash are the names of the parameters. Values are the values associated with those parameters in the incoming query. For parameters with multiple values, the value in this hash will be a list reference. This is the same behaviour as the "CGI" module's "Vars()" function. req my $req_object = $parser->req; Returns the "HTTP::Request" object. mime my $mime_object = $parser->mime; Returns the "Email::MIME" object. Now, you may be wondering why we're dealing with an "Email::MIME" object. The answer is simple. It's an amazing parser for MIME compliant messages, and RFC 822 compliant messages. When parsing incoming POST data, especially file uploads, "Email::MIME" is the perfect fit. It's fast and light. SEE ALSO "HTTP::Daemon", HTTP::Request, Email::MIME, CGI, perl. AUTHOR Casey West, . COPYRIGHT Copyright (c) 2005 Casey West. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.