Subject: | Incorrect use of HTTP::Request in compiled clients |
Date: | Thu, 22 Aug 2013 09:09:07 +0200 |
To: | bug-XML-Compile-SOAP [...] rt.cpan.org |
From: | Bret Lambert <bret.lambert [...] gmail.com> |
I noticed that, for processes which were long-running and connected to the
same server multiple times, each request would append the server's cookie
one more time, meaning that on request #N, I would have N copies of the
same cookie in the request. Obviously, this is not so awesome.
With the help of a friend who is more perl-capable than I, we tracked
the issue down to the reuse of HTTP:Request objects in the closures
returned when compiling clients. In reality, they should be new
objects for each request. Moving the request object creation into
the closures resolves the issue for me.
Diff below.
--- SOAPHTTP.pm.orig Thu Aug 22 08:48:21 2013
+++ SOAPHTTP.pm Thu Aug 22 08:58:33 2013
@@ -119,14 +119,6 @@
, method => $method;
}
- # Prepare request
-
- # Ideally, we should change server when one fails, and stick to that
- # one as long as possible.
- my $server = $self->address;
- my $request = HTTP::Request->new($method => $server, $header);
- $request->protocol('HTTP/1.1');
-
# Create handler
my ($create_message, $parse_message)
@@ -142,6 +134,13 @@
$hook
? sub # hooked code
{ my $trace = $_[1];
+
+ # Prepare request
+
+ my $server = $self->address;
+ my $request = HTTP::Request->new($method => $server, $header);
+ $request->protocol('HTTP/1.1');
+
$create_message->($request, $_[0], $_[2]);
$trace->{http_request} = $request;
@@ -172,6 +171,13 @@
: sub # real call
{ my $trace = $_[1];
+
+ # Prepare request
+
+ my $server = $self->address;
+ my $request = HTTP::Request->new($method => $server, $header);
+ $request->protocol('HTTP/1.1');
+
$create_message->($request, $_[0], $_[2]);
$trace->{http_request} = $request;