Skip Menu |
 

This queue is for tickets about the AnyEvent-HTTPD CPAN distribution.

Report information
The Basics
Id: 45131
Status: resolved
Priority: 0/
Queue: AnyEvent-HTTPD

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

Bug Information
Severity: Normal
Broken in: 0.04
Fixed in: (no value)



Subject: HTTP headers are not processed case-insensitive
Download (untitled) / with headers
text/plain 502b
AnyEvent::HTTPD::HTTPConnection works with HTTP headers case-sensitive, using versions of header names like 'Content-Disposition', 'Content-Length'. This causes interoperability problems with, say AnyEvent::HTTP client, which first lowercases headers and then uppercases their first letters. The simpliest solution is to lowercase accepted headers like AnyEvent::HTTP does. This may influence current users of AnyEvent::HTTPD, of course. The patch which implements lowercasing approach is attached.
Subject: ci.patch
Download ci.patch
text/x-diff 2.2k
commit 00cab1c65d4f0f97853bce86c7c3ccc1c5a2ae1e Author: Andrey Smirnov <allter@gmail.com> Date: Sun Apr 19 00:47:22 2009 +0400 Case-insensitive HTTP headers diff --git a/socketfarm/AnyEvent/HTTPD/HTTPConnection.pm b/socketfarm/AnyEvent/HTTPD/HTTPConnection.pm index efa15e5..84705e9 100644 --- a/socketfarm/AnyEvent/HTTPD/HTTPConnection.pm +++ b/socketfarm/AnyEvent/HTTPD/HTTPConnection.pm @@ -108,7 +108,7 @@ sub _parse_headers { \015\012 /sgx) { - $hdr->{$1} .= ",$2" + $hdr->{lc $1} .= ",$2" } for (keys %$hdr) { $hdr->{$_} = substr $hdr->{$_}, 1; } $hdr @@ -118,11 +118,11 @@ sub decode_part { my ($self, $hdr, $cont) = @_; $hdr = _parse_headers ($hdr); - if ($hdr->{'Content-Disposition'} =~ /form-data/) { - my ($dat, $name_para) = split /\s*;\s*/, $hdr->{'Content-Disposition'}; + if ($hdr->{lc 'Content-Disposition'} =~ /form-data/) { + my ($dat, $name_para) = split /\s*;\s*/, $hdr->{lc 'Content-Disposition'}; my ($name, $par) = split /\s*=\s*/, $name_para; if ($par =~ /^".*"$/) { $par = _unquote ($par) } - return ($par, $cont, $hdr->{'Content-Type'}); + return ($par, $cont, $hdr->{lc 'Content-Type'}); } (); } @@ -190,7 +190,7 @@ sub parse_urlencoded { sub handle_request { my ($self, $method, $uri, $hdr, $cont) = @_; - my ($c, @params) = split /\s*;\s*/, $hdr->{'Content-Type'}; + my ($c, @params) = split /\s*;\s*/, $hdr->{lc 'Content-Type'}; my $bound; for (@params) { if (/^\s*boundary\s*=\s*(.*?)\s*$/) { @@ -211,7 +211,7 @@ sub handle_request { sub handle_data { my ($self, $rbuf) = @_; - if ($self->{content_len}) { + if (defined $self->{content_len}) { if ($self->{content_len} <= length $$rbuf) { my $cont = substr $$rbuf, 0, $self->{content_len}; $$rbuf = substr $$rbuf, $self->{content_len}; @@ -241,8 +241,8 @@ sub handle_data { $self->{last_header} = [$m, $u, $hdr]; - if (defined $hdr->{'Content-Length'}) { - $self->{content_len} = $hdr->{'Content-Length'}; + if (defined $hdr->{lc 'Content-Length'}) { + $self->{content_len} = $hdr->{lc 'Content-Length'}; $self->handle_data ($rbuf); } else { $self->handle_request (@{$self->{last_header}});
Download (untitled) / with headers
text/plain 286b
Суб. Апр. 18 16:56:23 2009, allter писал: Show quoted text
> The patch which implements lowercasing approach is attached.
P.S. Also this patch fixes problem with requests with empty body and "Content-Length: 0" by using "defined" operator in "if( defined $self->{content_len} )" -- Andrey
Subject: Re: [rt.cpan.org #45131] HTTP headers are not processed case-insensitive
Date: Sun, 19 Apr 2009 08:45:09 +0200
To: "Andrey M. Smirnov via RT" <bug-AnyEvent-HTTPD [...] rt.cpan.org>
From: Robin Redeker <elmex [...] ta-sa.org>
Download (untitled) / with headers
text/plain 1.1k
On Sat, Apr 18, 2009 at 05:00:40PM -0400, Andrey M. Smirnov via RT wrote: Show quoted text
> Queue: AnyEvent-HTTPD > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=45131 > > > Суб. Апр. 18 16:56:23 2009, allter писал: >
> > The patch which implements lowercasing approach is attached.
> > P.S. Also this patch fixes problem with requests with empty body and > "Content-Length: 0" by using "defined" operator in "if( defined > $self->{content_len} )" >
Thanks a lot for the reports and even patches! But i've indeed recently rewrote exactly those parts of the HTTP implementation of AnyEvent::HTTPD. I just needed to test it in 'production' use before I wanted to release it. You may try the version in my git repository: Web viewer: http://git.ta-sa.org/AnyEvent-HTTPD.git git-clone http://git.ta-sa.org/AnyEvent-HTTPD.git I've added the repository to the main pod page of AE::HTTPD now. Thanks for the feedback! Robin -- Robin Redeker | Deliantra, the free code+content MORPG elmex@ta-sa.org / r.redeker@gmail.com | http://www.deliantra.net http://www.ta-sa.org/ |
Setting status to resolved: It's fixed in the repository and fix will be in the next release.


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.