Subject: | HTTP::Daemon sends invalid Content-Length for wide character content (fixed) |
The Content-Length HTTP header should represent the number of bytes to
expect.
The length(EXPR) function in Perl returns the number of characters.
For content with wide characters, the length(EXPR) of the string is not
equal to the number of bytes.
This causes web browsers to stop reading before the entire page is loaded.
To get the length in bytes, one should use "do { use bytes; length(EXPR) }".
The attached patch fixes the problem.
% perl -v
This is perl, v5.6.1 built for i386-linux
% uname -a
Linux barracuda 2.4.21 #5 SMP Wed Jan 7 15:17:13 UTC 2004 i686 unknown
Subject: | HTTP_Daemon.patch |
--- Daemon.pm.old Mon Aug 20 12:00:36 2007
+++ Daemon.pm Mon Aug 20 11:59:07 2007
@@ -228,7 +228,7 @@
# pretend it was a normal entity body
$r->remove_header('Transfer-Encoding');
- $r->header('Content-Length', length($body));
+ $r->header('Content-Length', do { use bytes; length($body) });
my($key, $val);
FOOTER:
@@ -436,7 +436,7 @@
}
}
elsif (length($content)) {
- $res->header("Content-Length" => length($content));
+ $res->header("Content-Length" => do { use bytes; length($content) });
}
else {
$self->force_last_request;
@@ -498,7 +498,7 @@
unless ($self->antique_client) {
$self->send_basic_header($status);
print $self "Content-Type: text/html$CRLF";
- print $self "Content-Length: " . length($mess) . $CRLF;
+ print $self "Content-Length: " . do { use bytes; length($mess) } . $CRLF;
print $self $CRLF;
}
print $self $mess;