[Catalyst-commits] r6194 - in branches/HTTP-Body: . lib/HTTP
lib/HTTP/Body t/data/urlencoded
andyg at dev.catalyst.perl.org
andyg at dev.catalyst.perl.org
Sat Mar 24 03:47:33 GMT 2007
Author: andyg
Date: 2007-03-24 03:47:33 +0000 (Sat, 24 Mar 2007)
New Revision: 6194
Modified:
branches/HTTP-Body/Changes
branches/HTTP-Body/lib/HTTP/Body.pm
branches/HTTP-Body/lib/HTTP/Body/UrlEncoded.pm
branches/HTTP-Body/t/data/urlencoded/001-content.dat
branches/HTTP-Body/t/data/urlencoded/001-headers.yml
branches/HTTP-Body/t/data/urlencoded/001-results.yml
Log:
HTTP::Body - small performance tweaks to urlencoded parser
Modified: branches/HTTP-Body/Changes
===================================================================
--- branches/HTTP-Body/Changes 2007-03-24 02:26:04 UTC (rev 6193)
+++ branches/HTTP-Body/Changes 2007-03-24 03:47:33 UTC (rev 6194)
@@ -1,5 +1,8 @@
This file documents the revision history for Perl extension HTTP::Body.
+0.9
+ - Small performance tweaks to urlencoded parser.
+
0.8 2007-03-23 18:40:00
- Some browsers such as MSIE send extra data after the body content. We now
properly ignore anything beyond Content-Length.
Modified: branches/HTTP-Body/lib/HTTP/Body/UrlEncoded.pm
===================================================================
--- branches/HTTP-Body/lib/HTTP/Body/UrlEncoded.pm 2007-03-24 02:26:04 UTC (rev 6193)
+++ branches/HTTP-Body/lib/HTTP/Body/UrlEncoded.pm 2007-03-24 03:47:33 UTC (rev 6194)
@@ -6,6 +6,15 @@
our $DECODE = qr/%([0-9a-fA-F]{2})/;
+our %hex_chr;
+
+BEGIN {
+ for my $num ( 0 .. 255 ) {
+ my $h = sprintf "%02X", $num;
+ $hex_chr{ lc $h } = $hex_chr{ uc $h } = chr $num;
+ }
+}
+
=head1 NAME
HTTP::Body::UrlEncoded - HTTP Body UrlEncoded Parser
@@ -30,6 +39,8 @@
my $self = shift;
return unless $self->length == $self->content_length;
+
+ $self->{buffer} =~ tr/+/ /;
for my $pair ( split( /[&;]/, $self->{buffer} ) ) {
@@ -37,12 +48,10 @@
next unless defined $name;
next unless defined $value;
+
+ $name =~ s/$DECODE/$hex_chr{$1}/gs;
+ $value =~ s/$DECODE/$hex_chr{$1}/gs;
- $name =~ tr/+/ /;
- $name =~ s/$DECODE/chr(hex($1))/eg;
- $value =~ tr/+/ /;
- $value =~ s/$DECODE/chr(hex($1))/eg;
-
$self->param( $name, $value );
}
Modified: branches/HTTP-Body/lib/HTTP/Body.pm
===================================================================
--- branches/HTTP-Body/lib/HTTP/Body.pm 2007-03-24 02:26:04 UTC (rev 6193)
+++ branches/HTTP-Body/lib/HTTP/Body.pm 2007-03-24 03:47:33 UTC (rev 6194)
@@ -4,7 +4,7 @@
use Carp qw[ ];
-our $VERSION = 0.8;
+our $VERSION = 0.9;
our $TYPES = {
'application/octet-stream' => 'HTTP::Body::OctetStream',
Modified: branches/HTTP-Body/t/data/urlencoded/001-content.dat
===================================================================
--- branches/HTTP-Body/t/data/urlencoded/001-content.dat 2007-03-24 02:26:04 UTC (rev 6193)
+++ branches/HTTP-Body/t/data/urlencoded/001-content.dat 2007-03-24 03:47:33 UTC (rev 6194)
@@ -1 +1 @@
-text1=Ratione+accusamus+aspernatur+aliquam&text2=%C3%A5%C3%A4%C3%B6%C3%A5%C3%A4%C3%B6&select=A&select=B&textarea=Voluptatem+cumque+voluptate+sit+recusandae+at.+Et+quas+facere+rerum+unde+esse.+Sit+est+et+voluptatem.+Vel+temporibus+velit+neque+odio+non.%0D%0A%0D%0AMolestias+rerum+ut+sapiente+facere+repellendus+illo.+Eum+nulla+quis+aut.+Quidem+voluptas+vitae+ipsam+officia+voluptatibus+eveniet.+Aspernatur+cupiditate+ratione+aliquam+quidem+corrupti.+Eos+sunt+rerum+non+optio+culpa.
\ No newline at end of file
+text1=Ratione+accusamus+aspernatur+aliquam&text2=%C3%A5%C3%A4%C3%B6%C3%A5%C3%A4%C3%B6&select=A&select=B&textarea=Voluptatem+cumque+voluptate+sit+recusandae+at.+Et+quas+facere+rerum+unde+esse.+Sit+est+et+voluptatem.+Vel+temporibus+velit+neque+odio+non.%0D%0A%0D%0AMolestias+rerum+ut+sapiente+facere+repellendus+illo.+Eum+nulla+quis+aut.+Quidem+voluptas+vitae+ipsam+officia+voluptatibus+eveniet.+Aspernatur+cupiditate+ratione+aliquam+quidem+corrupti.+Eos+sunt+rerum+non+optio+culpa.&encoding=foo%3Dbar
\ No newline at end of file
Modified: branches/HTTP-Body/t/data/urlencoded/001-headers.yml
===================================================================
--- branches/HTTP-Body/t/data/urlencoded/001-headers.yml 2007-03-24 02:26:04 UTC (rev 6193)
+++ branches/HTTP-Body/t/data/urlencoded/001-headers.yml 2007-03-24 03:47:33 UTC (rev 6194)
@@ -1,4 +1,4 @@
---
-Content-Length: 480
+Content-Length: 499
Content-Type: application/x-www-form-urlencoded
User-Agent: 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312'
Modified: branches/HTTP-Body/t/data/urlencoded/001-results.yml
===================================================================
--- branches/HTTP-Body/t/data/urlencoded/001-results.yml 2007-03-24 02:26:04 UTC (rev 6193)
+++ branches/HTTP-Body/t/data/urlencoded/001-results.yml 2007-03-24 03:47:33 UTC (rev 6194)
@@ -7,4 +7,5 @@
text1: Ratione accusamus aspernatur aliquam
text2: åäöåäö
textarea: "Voluptatem cumque voluptate sit recusandae at. Et quas facere rerum unde esse. Sit est et voluptatem. Vel temporibus velit neque odio non.\r\n\r\nMolestias rerum ut sapiente facere repellendus illo. Eum nulla quis aut. Quidem voluptas vitae ipsam officia voluptatibus eveniet. Aspernatur cupiditate ratione aliquam quidem corrupti. Eos sunt rerum non optio culpa."
+ encoding: foo=bar
upload: {}
More information about the Catalyst-commits
mailing list