Skip Menu |
 

This queue is for tickets about the libwww-perl CPAN distribution.

Report information
The Basics
Id: 41462
Status: resolved
Priority: 0/
Queue: libwww-perl

People
Owner: Nobody in particular
Requestors: AGRUNDMA [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 5.821
Fixed in: (no value)



Subject: Content-Length header duplicated in _simple_req
Download (untitled) / with headers
text/plain 306b
The following line was added recently, and it adds a redundant Content-Length header if the Content-Length line is passed after Content: HTTP::Request::Common line 108: $req->header("Content-Length", length(${$req->content_ref})); See the attached test script. This line should probably just be removed.
Subject: clbug.pl
Download clbug.pl
text/x-perl 273b
#!/usr/bin/perl use strict; use Data::Dump qw(dump); use HTTP::Request::Common; my $request = PUT( 'http://localhost/', 'Content-Type' => 'application/octet-stream', 'Content' => 'foobarbaz', 'Content-Length' => 9, ); warn dump($request) . "\n";
Download (untitled) / with headers
text/plain 549b
On Fri Dec 05 12:07:19 2008, AGRUNDMA wrote: Show quoted text
> The following line was added recently, and it adds a redundant > Content-Length header if the Content-Length line is passed after Content: > > HTTP::Request::Common line 108: > $req->header("Content-Length", length(${$req->content_ref})); > > See the attached test script. This line should probably just be removed.
The line was added in response to RT#34772 so I would like to keep it. It just need to be defered until we know that there is no explict content-length header provided as well.
Download (untitled) / with headers
text/plain 1.7k
I've now applied the following patch <http://gitorious.org/projects/libwww- perl/repos/mainline/commits/5a04f678e229a505f3fc7f1073cfe85342abb68e> commit 5a04f678e229a505f3fc7f1073cfe85342abb68e Author: Gisle Aas <gisle@aas.no> Date: Fri Dec 5 10:09:21 2008 -0800 Prefer use specified Content-Length header [RT#41462] We ended up with a double Content-Length header when the user specified one explictly. diff --git a/lib/HTTP/Request/Common.pm b/lib/HTTP/Request/Common.pm index 9b342d1..26ad747 100644 --- a/lib/HTTP/Request/Common.pm +++ b/lib/HTTP/Request/Common.pm @@ -102,15 +102,19 @@ sub _simple_req my($method, $url) = splice(@_, 0, 2); my $req = HTTP::Request->new($method => $url); my($k, $v); + my $content; while (($k,$v) = splice(@_, 0, 2)) { if (lc($k) eq 'content') { $req->add_content($v); - $req->header("Content-Length", length(${$req->content_ref})); + $content++; } else { $req->push_header($k, $v); } } + if ($content && !defined($req->header("Content-Length"))) { + $req->header("Content-Length", length(${$req->content_ref})); + } $req; } diff --git a/t/base/common-req.t b/t/base/common-req.t index acb4c53..86fe116 100644 --- a/t/base/common-req.t +++ b/t/base/common-req.t @@ -1,7 +1,7 @@ #perl -w use Test; -plan tests => 51; +plan tests => 52; use HTTP::Request::Common; @@ -205,3 +205,9 @@ EOT $r = HTTP::Request::Common::DELETE 'http://www.example.com'; ok($r->method, "DELETE"); + +$r = HTTP::Request::Common::PUT 'http://www.example.com', + 'Content-Type' => 'application/octet-steam', + 'Content' => 'foobarbaz', + 'Content-Length' => 12; # a slight lie +ok($r->header('Content-Length'), 12); d


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.