Changing default behavior of upload handling to stop taking over the upload extension...
[catagits/HTTP-Body.git] / lib / HTTP / Body / UrlEncoded.pm
1 package HTTP::Body::UrlEncoded;
2
3 use strict;
4 use base 'HTTP::Body';
5 use bytes;
6
7 our $DECODE = qr/%([0-9a-fA-F]{2})/;
8
9 our %hex_chr;
10
11 for my $num ( 0 .. 255 ) {
12     my $h = sprintf "%02X", $num;
13     $hex_chr{ lc $h } = $hex_chr{ uc $h } = chr $num;
14 }
15
16 =head1 NAME
17
18 HTTP::Body::UrlEncoded - HTTP Body UrlEncoded Parser
19
20 =head1 SYNOPSIS
21
22     use HTTP::Body::UrlEncoded;
23
24 =head1 DESCRIPTION
25
26 HTTP Body UrlEncoded Parser.
27
28 =head1 METHODS
29
30 =over 4
31
32 =item spin
33
34 =cut
35
36 sub spin {
37     my $self = shift;
38
39     return unless $self->length == $self->content_length;
40     
41     # I tested parsing this using APR::Request, but perl is faster
42     # Pure-Perl    2560/s
43     # APR::Request 2305/s
44     
45     # Note: s/// appears faster than tr///
46     $self->{buffer} =~ s/\+/ /g;
47
48     for my $pair ( split( /[&;](?:\s+)?/, $self->{buffer} ) ) {
49
50         my ( $name, $value ) = split( /=/, $pair , 2 );
51
52         next unless defined $name;
53         next unless defined $value;
54         
55         $name  =~ s/$DECODE/$hex_chr{$1}/gs;
56         $value =~ s/$DECODE/$hex_chr{$1}/gs;
57
58         $self->param( $name, $value );
59     }
60
61     $self->{buffer} = '';
62     $self->{state}  = 'done';
63 }
64
65 =back
66
67 =head1 SUPPORT
68
69 See L<HTTP::Body>
70
71 =head1 AUTHORS
72
73 Christian Hansen, C<ch@ngmedia.com>
74
75 Andy Grundman, C<andy@hybridized.org>
76
77 =head1 LICENSE
78
79 This library is free software . You can redistribute it and/or modify 
80 it under the same terms as perl itself.
81
82 =cut
83
84 1;