Skip Menu |

This queue is for tickets about the HTTP-Client CPAN distribution.

Report information
The Basics
Id: 79889
Status: resolved
Priority: 0/
Queue: HTTP-Client

People
Owner: Nobody in particular
Requestors: akotov [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 1.53
Fixed in: 1.54



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.
Working on this - thanks for the report. If you're just starting out, you might want to consider using a different library. Have a look at this review of all the CPAN modules (that I was aware of) for making HTTP requests: http://neilb.org/reviews/http-requesters.html A good place to start is HTTP::Tiny.
Quick fix is making its way round CPAN as 1.54. Slightly longer term I'll also fix it so each instance of HTTP::Client creates its own instance of HTTP::Lite. Cheers, Neil
Subject: Re: [rt.cpan.org #79889] HTTP::Client concatenates results of GET calls
Date: Thu, 27 Sep 2012 15:29:48 -0700
To: bug-HTTP-Client [...] rt.cpan.org
From: "Alex K." <akotov [...] gmail.com>
Thanks for the quick fix! I'll give it a try. - Alex On Thu, Sep 27, 2012 at 2:51 PM, Neil_Bowers via RT <bug-HTTP-Client@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=79889 > > > Quick fix is making its way round CPAN as 1.54. > > Slightly longer term I'll also fix it so each instance of HTTP::Client creates its own instance of > HTTP::Lite. > > Cheers, > Neil