[Catalyst-dev] Catalyst::Test and POSTing non-form data
    Christopher H. Laco 
    claco at chrislaco.com
       
    Mon Aug 18 19:09:53 BST 2008
    
    
  
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?
http://perldoc.perl.org/functions/length.html
> Note the characters: if the EXPR is in Unicode, you will get the number of characters, not the number of bytes. To get the length of the internal string in bytes, use bytes::length(EXPR) , see bytes. Note that the internal encoding is variable, and the number of bytes usually meaningless. To get the number of bytes that the string would have when encoded as UTF-8, use length(Encoding::encode_utf8(EXPR)).
-=Chris
    
    
More information about the Catalyst-dev
mailing list