DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Fix Content-Length Header On UTF8 With HTTP::Daemon In Perl

07.17.2006
| 6275 views |
  • submit to reddit
        
It seems that HTTP/Daemon.pm is bogus when it calculate
the header 'Content-Length' when the data contains UTF8 data .

In attachement a patch , to calculate the length in bytes
of the data .

-- 
     ____________________________________________________________
    / Erwan MAS                                                 /\
   | mailto:[EMAIL PROTECTED]                                   |_/
___|________________________________________________________   |
\___________________________________________________________\__/

--- Daemon.pm.orig      2004-12-11 16:13:22.000000000 +0100
+++ Daemon.pm   2006-05-02 22:53:33.660393022 +0200
@@ -436,7 +436,7 @@
            }
        }
        elsif (length($content)) {
-           $res->header("Content-Length" => length($content));
+           $res->header("Content-Length" => bytes::length($content));
        }
        else {
            $self->force_last_request;