| 1 | package POE::Component::Server::HTTPServer::ParameterParseHandler; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use HTTP::Status; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use MIME::Types; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use URI::Escape qw(uri_unescape); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use POE::Component::Server::HTTPServer::Handler; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use base 'POE::Component::Server::HTTPServer::Handler'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | # | ||||||||||
| 10 | # problems to fix: | ||||||||||
| 11 | # multi-valued params | ||||||||||
| 12 | # mutlipart form data | ||||||||||
| 13 | # the hash copying at the end of the POST handling could be more efficient | ||||||||||
| 14 | # | ||||||||||
| 15 | 4 | ▶ | sub handle { | ||||||||
|
Subroutine
handle: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||
| 16 | 4 | my $self = shift; | |||||||||
| 17 | 4 | my $context = shift; | |||||||||
| 18 | 4 | my $req = $context->{request}; | |||||||||
| 19 | # technically, for POST requests we could ignore (uri-)query params | ||||||||||
| 20 | # might as well grab them, though | ||||||||||
| 21 | 4 | my %p = $req->uri->query_form; | |||||||||
| 22 | 4 | $context->{param} = \%p; | |||||||||
| 23 | 4 | ▶ | if ( $req->method eq 'POST' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 2 | ▶ | if ( $req->content_type ne 'application/x-www-form-urlencoded' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 0 | print "XXX Don't know how to handle POST content encoding: ", | |||||||||
| 26 | $req->content_type, "\n"; | ||||||||||
| 27 | } else { | ||||||||||
| 28 | 2 | my $querydata = $req->content; | |||||||||
| 29 | # following mapmap stolen from URI::_query | ||||||||||
| 30 | 6 | my %bodyp = map { s/\+/ /g; uri_unescape($_) } | |||||||||
| 31 | 2 | ▶ | map { /=/ ? split(/=/, $_, 2) : ($_ => '')} split(/&/, $querydata); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 2 | foreach my $k (keys %bodyp) { | |||||||||
| 33 | 3 | $context->{param}->{$k} = $bodyp{$k}; | |||||||||
| 34 | } | ||||||||||
| 35 | } | ||||||||||
| 36 | } | ||||||||||
| 37 | 4 | return H_CONT; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 1 | 1; | |||||||||
| 41 | __END__ | ||||||||||