Skip Menu |

This queue is for tickets about the LWP-Protocol-AnyEvent-http CPAN distribution.

Report information
The Basics
Id: 80600
Status: resolved
Priority: 0/
Queue: LWP-Protocol-AnyEvent-http

People
Owner: Nobody in particular
Requestors: pagenyon [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: v1.8.0



Subject: handle headers with embedded newlines
LWP::Protocol::http handles header values with embedded newlines by replacing them with spaces. LWP::Protocol::AnyEvent::http should do the same.
From: pagenyon [...] gmail.com
On Sat Nov 03 08:50:15 2012, pagenyon wrote: Show quoted text
> LWP::Protocol::http handles header values with embedded newlines by > replacing them with spaces. LWP::Protocol::AnyEvent::http should do the > same.
Example code demonstrating problem and showing that LWP::Protocol::http handles it okay: http://www.perlmonks.org/?node_id=1001399
Subject: Re: [rt.cpan.org #80600] handle headers with embedded newlines
Date: Sun, 4 Nov 2012 00:55:50 -0400
To: bug-LWP-Protocol-AnyEvent-http [...] rt.cpan.org
From: Eric Brine <ikegami [...] adaelis.com>
On Sat, Nov 3, 2012 at 8:48 PM, pagenyon via RT < bug-LWP-Protocol-AnyEvent-http@rt.cpan.org> wrote: Show quoted text
> Queue: LWP-Protocol-AnyEvent-http > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=80600 > > > On Sat Nov 03 08:50:15 2012, pagenyon wrote:
> > LWP::Protocol::http handles header values with embedded newlines by > > replacing them with spaces. LWP::Protocol::AnyEvent::http should do the > > same.
> > Example code demonstrating problem and showing that LWP::Protocol::http > handles it okay: > http://www.perlmonks.org/?node_id=1001399 >
Neither of those requests header values with embedded newlines.
Subject: Re: [rt.cpan.org #80600] handle headers with embedded newlines
Date: Sun, 4 Nov 2012 01:46:41 -0400
To: bug-LWP-Protocol-AnyEvent-http [...] rt.cpan.org
From: Eric Brine <ikegami [...] adaelis.com>
On Sat, Nov 3, 2012 at 8:50 AM, pagenyon via RT < bug-LWP-Protocol-AnyEvent-http@rt.cpan.org> wrote: Show quoted text
> LWP::Protocol::http handles header values with embedded newlines by > replacing them with spaces. LWP::Protocol::AnyEvent::http should do the > same. >
Indeed. Test server: $ perl -MIO::Socket::INET -e' my $s = IO::Socket::INET->new(LocalPort=>12345,Listen=>1) or die $!; my $c = $s->accept; sleep 1; $c->print("HTTP/1.1 200 OK\r\n"); $c->print("Connection: Close\r\n"); $c->print("Content-Length: 4\r\n"); $c->print("Content-Type: text/html\r\n"); $c->print("FooBar: foo\r\n"); $c->print(" bar\r\n"); $c->print("\r\n"); $c->print("xxx\n"); sleep 1; ' Normal LWP: Show quoted text
>perl -MLWP -E"$ua = LWP::UserAgent->new(); print $ua->get('
http://127.0.0.1:12345/')->as_string" HTTP/1.1 200 OK Connection: Close Content-Length: 4 Content-Type: text/html Client-Date: Sun, 04 Nov 2012 05:37:03 GMT Client-Peer: 127.0.0.1:12345 Client-Response-Num: 1 FooBar: foo bar xxx With LWP::Protocol::AnyEvent::http: Show quoted text
>perl -MLWP::Protocol::AnyEvent::http -MLWP -E"$ua = LWP::UserAgent->new();
print $ua->get('http://127.0.0.1:12345/')->as_string" HTTP/1.1 200 OK Connection: Close Content-Length: 4 Content-Type: text/html Client-Date: Sun, 04 Nov 2012 05:41:09 GMT Foobar: foo bar X-AE-URL: http://127.0.0.1:12345/ xxx As far as I can tell, those two headers should be considered equivalent, which means: 1. You're working with buggy code if this is causing you problems. 2. There's no harm in machting LWP's normal behaviour. I'm on it. - Eric
1.0.6 replaces newlines in the same way as Net::HTTP does. 1.0.6 should make its way to your CPAN mirror over the next 24 hours.
From: pagenyon [...] gmail.com
On Sun Nov 04 01:43:47 2012, ikegami wrote: Show quoted text
> 1.0.6 replaces newlines in the same way as Net::HTTP does. > > 1.0.6 should make its way to your CPAN mirror over the next 24 hours.
The headers in the request needs fixing, not the response headers. I am attaching a patch.
Subject: headers.patch
diff --git a/lib/LWP/Protocol/AnyEvent/http.pm b/lib/LWP/Protocol/AnyEvent/http.pm index 0ea94b8..831daac 100644 --- a/lib/LWP/Protocol/AnyEvent/http.pm +++ b/lib/LWP/Protocol/AnyEvent/http.pm @@ -74,10 +74,6 @@ sub _set_response_headers { ]; } - # Imitate Net::HTTP's removal of newlines. - s/\s*\n\s+/ /g - for values %headers; - $response->header(%headers); } @@ -87,7 +83,11 @@ sub request { my $method = $request->method(); my $url = $request->uri(); - my %headers; $request->headers()->scan(sub { $headers{ lc($_[0]) } = $_[1]; }); + my %headers; $request->headers()->scan(sub { + # Imitate LWP::Protocol::http's removal of newlines. + $_[1] =~ s/\n/ /g; + $headers{ lc($_[0]) } = $_[1]; + }); my $body = $request->content_ref(); # Fix AnyEvent::HTTP setting Referer to the request URL
On Wed Jul 31 07:30:11 2013, pagenyon wrote: Show quoted text
> On Sun Nov 04 01:43:47 2012, ikegami wrote:
> > 1.0.6 replaces newlines in the same way as Net::HTTP does. > > > > 1.0.6 should make its way to your CPAN mirror over the next 24 hours.
> > The headers in the request needs fixing, not the response headers. I > am attaching a patch.
I adding the request "fixing" as requested. This will be published shortly. Note: I didn't remove the response "fixing". I don't know why you included that in your patch. Note: It's not proper to modify $_[1] as it'll modify the arg in the caller. It would also fail if the caller passes a constant. One must make a copy and modify that instead.