Subject: | Patch to add Content-Length for POST requests |
I'm using the transport_hook option of $wsdl->compileClient() to use the Catalyst test
server. However, the HTTP::Request sent does not have a Content-Length header which
makes Catalyst think there is no body. The patch below adds that header.
Note: I'm not sure how this handles unicode. I may be doing that part right, but I'm still a
newbie with Unicode.
Drew
drew@skidoo ../XML/Compile/Transport$ diff -u SOAPHTTP.pm.orig SOAPHTTP.pm
--- SOAPHTTP.pm.orig 2008-04-09 16:44:06.000000000 +0100
+++ SOAPHTTP.pm 2008-04-09 16:47:22.000000000 +0100
@@ -121,11 +121,16 @@
$hook
? sub # hooked code
{ my $trace = $_[1];
+ my $length;
if(utf8::is_utf8($_[0]))
{ my $u = encode($charset, $_[0]);
+ $length = length $u;
$request->content($u);
}
- else { $request->content($_[0]) }
+ else { $length = length $_[0]; $request->content($_[0]) }
+ # Content-Length header is needed only for POSTs
+ $request->header("Content-Length", $length)
+ if uc $request->method eq 'POST';
$trace->{http_request} = $request;
$trace->{action} = $action;