[Catalyst-dev] Catalyst::Test and POSTing non-form data
Jonathan Rockway
jon at jrock.us
Mon Aug 18 19:50:05 BST 2008
* On Mon, Aug 18 2008, Christopher H. Laco wrote:
> Rafael Kitover wrote:
>> Here's a small patch which adds a Content-Length header if it's not in
>> the request object passed to Catalyst::Test
>>
>> Index: lib/Catalyst/Utils.pm
>> ===================================================================
>> --- lib/Catalyst/Utils.pm (revision 8230)
>> +++ lib/Catalyst/Utils.pm (working copy)
>> @@ -233,6 +233,13 @@
>> unless ( ref $request eq 'HTTP::Request' ) {
>> $request = HTTP::Request->new( 'GET', $request );
>> }
>> +
>> + if (defined $request->content
>> + && !defined $request->header('Content-Length')) {
>> + use bytes;
>> + $request->header('Content-Length' => length $request->content);
>> + }
>> +
>> return $request;
>> }
>
> That's going to break when unicode is involved is it not?
I don't think you can get reliable behavior when you put raw perl
characters in the HTTP::Request object anyway. If you want to send a
unicode request, you need to encode the characters into bytes and set
the appropriate content-type header. So at that point, "length" will be
correct.
The real problem is the lack of a helper that automates this. Maybe
mech does, but I wouldn't count on it since mech goes out of its way to
be useless with anything other than ASCII.
Regards,
Jonathan Rockway
--
print just => another => perl => hacker => if $,=$"
More information about the Catalyst-dev
mailing list