Skip to content

Instantly share code, notes, and snippets.

Created March 1, 2011 19:44
Show Gist options
  • Save anonymous/849741 to your computer and use it in GitHub Desktop.
Save anonymous/849741 to your computer and use it in GitHub Desktop.
diff -ur old/Parser.pm new/Parser.pm
--- old/Parser.pm 2010-06-15 13:57:43.000000000 -0500
+++ new/Parser.pm 2011-03-01 13:44:02.000000000 -0600
@@ -260,6 +260,12 @@
unless $http and $http =~ /^HTTP\/(\d+)\.(\d+)$/i;
($major,$minor) = ($1,$2);
die 'HTTP requests not allowed' unless $self->{request};
+
+ # If the requested uri was relative, we need to tell URI that we don't
+ # know the scheme, otherwise it will interpret paths that start with a
+ # double slash as a scheme-relative url, and $req->uri->path will be
+ # wrong.
+ $uri = "//$uri" if $uri =~ m(^/);
$obj = $self->{obj} = HTTP::Request->new($method, URI->new($uri));
}
diff -ur old/t/1.t new/t/1.t
--- old/t/1.t 2007-02-24 08:54:48.000000000 -0600
+++ new/t/1.t 2011-03-01 13:34:34.000000000 -0600
@@ -4,7 +4,7 @@
#########################
use strict;
-use Test::More tests => 21;
+use Test::More tests => 22;
# <1>
BEGIN { use_ok('HTTP::Parser') };
@@ -77,3 +77,7 @@
is($res->content, "Some content!\x0d\x0a", 'content is correct');
}
+# <1>
+$parser = HTTP::Parser->new(request => 1);
+$parser->add("GET //foo///bar/baz HTTP/1.1\x0d\x0a\x0d\x0a");
+is $parser->request->uri->path, '//foo///bar/baz';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment