Subject: | HTTP headers are not processed case-insensitive |
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 |
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}});