I'm trying to upload a file to a server, but it's failing because the content-length is incorrect. This is because the content is UTF-8 and length() is reporting characters, not bytes.
Attached is a small test to demonstrate this.
I would imagine that somewhere in the bowels of HTTP::Request, bytes::length() needs to be used instead of the default CORE::length(), which reports characters. Or maybe call decode('utf8', $content). But that would involve knowing more about the character sets in use...
Annoyingly, tha attachment seems to hav been stripped off somewhere. Here's the code that used to be an attachment:
#!/usr/bin/perl -w
use strict; use warnings;
use Test::More;
use HTTP::Request::Common;
if ($] >= 5.007) {
plan tests => 2;
# This is all rather evil. :-(
binmode( STDOUT, ':utf8' );
Test::Builder->new->output( \*STDOUT );
Test::Builder->new->todo_output( \*STDOUT );
binmode( STDERR, ':utf8' );
Test::Builder->new->failure_output( \*STDERR );
} else {
plan skip_all => 'perl 5.7 or better required';
}my $req = POST 'http://example.com', Content_Type => 'text/plain', Content => "A"; is $req->content_length, 1, 'plain ascii has the correct length' or diag $req->as_string;
# If in doubt as to the output, pipe into "less -Kascii", including # stderr. $req = POST 'http://example.com', Content_Type => 'text/plain; charset=UTF-8', Content => "\x{100}"; is $req->content_length, 2, 'utf8 has the correct length' or diag $req->as_string;
# vim: set ai et sw=4 syntax=perl :
-Dom
