diff -urpN HTTP-Parser-0.04~/README HTTP-Parser-0.04/README --- HTTP-Parser-0.04~/README 2007-02-24 19:20:32.000000000 +0530 +++ HTTP-Parser-0.04/README 2009-03-23 06:29:10.000000000 +0530 @@ -13,18 +13,17 @@ e.g. my @lines = ('GET / HTTP/1.1','Host: localhost','Connection: close','',''); my $result; - while my $line(@lines) { + foreach my $line(@lines) { $result = $parser->add("$line\x0d\x0a"); print "passing '$line' got '$result'\n"; } - print $result->as_string(); + print $parser->object->as_string(); gives: - GET / + GET / HTTP/1.1 Connection: close Host: localhost - X-HTTP-Version: 1.1 INSTALLATION diff -urpN HTTP-Parser-0.04~/Parser.pm HTTP-Parser-0.04/Parser.pm --- HTTP-Parser-0.04~/Parser.pm 2007-11-11 04:09:21.000000000 +0530 +++ HTTP-Parser-0.04/Parser.pm 2009-03-23 06:25:36.000000000 +0530 @@ -111,8 +111,8 @@ system, on the other hand, it's quite al Ideally, the first chunk passed in is the header (up to the double newline), then whatever byte counts are requested. -When a request object is returned, the X-HTTP-Version header has the HTTP -version, the uri() method will always return a URI object, not a string. +When a request object is returned, the uri() method will always return a +URI object, not a string. Note that a nonzero return is just a hint, and any amount of data can be passed in to a subsequent add() call. @@ -225,12 +225,12 @@ sub _parse_header { # parse request or response line my $obj; unless($trailer) { - my ($major, $minor); + my ($proto); # is it an HTTP response? - if ($request =~ /^HTTP\/(\d+)\.(\d+)/i) { + if ($request =~ /^(HTTP\/\d+\.\d+)/i) { die 'HTTP responses not allowed' unless $self->{response}; - ($major,$minor) = ($1,$2); + $proto = $1; my (undef, $state, $msg) = split / /,$request; $obj = $self->{obj} = HTTP::Response->new($state, $msg); @@ -238,13 +238,13 @@ sub _parse_header { } else { my ($method,$uri,$http) = split / /,$request; die "'$request' is not the start of a valid HTTP request or response" - unless $http and $http =~ /^HTTP\/(\d+)\.(\d+)$/i; - ($major,$minor) = ($1,$2); + unless $http and $http =~ /^(HTTP\/\d+\.\d+)$/i; + $proto = $1; die 'HTTP requests not allowed' unless $self->{request}; $obj = $self->{obj} = HTTP::Request->new($method, URI->new($uri)); } - $obj->header(X_HTTP_Version => "$major.$minor"); # pseudo-header + $obj->protocol($proto); # we've already seen the initial line and created the object } else { diff -urpN HTTP-Parser-0.04~/t/1.t HTTP-Parser-0.04/t/1.t --- HTTP-Parser-0.04~/t/1.t 2007-02-24 20:24:48.000000000 +0530 +++ HTTP-Parser-0.04/t/1.t 2009-03-23 06:25:13.000000000 +0530 @@ -40,8 +40,7 @@ if($result) { my @head; $req->headers->scan(sub { push @head, [@_] }); - ok(eq_set(\@head,[[Connection => 'close'], [Host => 'localhost'], - ['X-HTTP-Version' => '1.1']]),'Headers'); + ok(eq_set(\@head,[[Connection => 'close'],[Host => 'localhost']]),'Headers'); is($req->content,'','Content'); }