Subject: | HTTP::Client concatenates results of GET calls |
Date: | Thu, 27 Sep 2012 13:36:13 -0700 |
To: | bug-HTTP-Client [...] rt.cpan.org |
From: | "Alex K." <akotov [...] gmail.com> |
HTTP::Client version: 1.53, downloaded from CPAN
HTTP::Lite version: 2.4, downloaded from CPAN
Perl version:
This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi
(with 53 registered patches, see perl -V for more detail)
OS: Ubuntu Linux 11.04
How to reproduce:
1. Create a standalone http server that responds with the same message
to every request. I used Ruby and Sinatra.
$ cat oneliner.rb
require 'rubygems'
require 'sinatra'
get '/' do
'httlo world'
end
Run the server: "ruby oneliner.rb"
Check:
$ curl http://localhost:4567/
httlo world$
2. Client to talk to the server:
$ cat http-client-bug.pl
use strict;
use HTTP::Client;
for (my $i = 0; $i< 10; $i++) {
my $res = get_url("http://localhost:4567/");
print "attempt $i, result $res\n";
}
sub get_url {
my $url = shift;
my $client = HTTP::Client->new();
my $res = $client->get($url);
return $res;
}
3. Run the client:
$ perl http-client-bug.pl
attempt 0, result httlo world
attempt 1, result httlo worldhttlo world
attempt 2, result httlo worldhttlo worldhttlo world
attempt 3, result httlo worldhttlo worldhttlo worldhttlo world
attempt 4, result httlo worldhttlo worldhttlo worldhttlo worldhttlo world
attempt 5, result httlo worldhttlo worldhttlo worldhttlo worldhttlo
worldhttlo world
attempt 6, result httlo worldhttlo worldhttlo worldhttlo worldhttlo
worldhttlo worldhttlo world
attempt 7, result httlo worldhttlo worldhttlo worldhttlo worldhttlo
worldhttlo worldhttlo worldhttlo world
attempt 8, result httlo worldhttlo worldhttlo worldhttlo worldhttlo
worldhttlo worldhttlo worldhttlo worldhttlo world
attempt 9, result httlo worldhttlo worldhttlo worldhttlo worldhttlo
worldhttlo worldhttlo worldhttlo worldhttlo worldhttlo world
Note that I'm creating a new instance of HTTP::Client for every
request and yet the results of GET are concatenated. Probably because
HTTP::Client uses a single instance of HTTP::Lite and does not call
reset() between requests.