Skip Menu |
 

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

Report information
The Basics
Id: 79285
Status: open
Priority: 0/
Queue: HTTP-Async

People
Owner: Nobody in particular
Requestors: p.tsopanoglou [...] mls.gr
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: "next_response" and "wait_for_next_response" methods, both initiate a new HTTP Request
Date: Wed, 29 Aug 2012 17:35:03 +0300
To: <bug-HTTP-Async [...] rt.cpan.org>
From: "Tsopanoglou Paschalis" <p.tsopanoglou [...] mls.gr>
Download (untitled) / with headers
text/plain 680b
Distribution: HTTP-Async-0.10 Perl version: 5.14.2 (Win32, Strawberry Perl) Operating system: Windows XP The "next_response" and "wait_for_next_response" methods, both initiate a new HTTP Request So the below program results in 2 requests instead of 1. #!/usr/bin/perl use warnings; use strict; use HTTP::Async; use HTTP::Request; my $downloader=HTTP::Async->new; $downloader->add(HTTP::Request->new('GET','http://www.deltahacker.gr/')) ; #First request while (my $response=$downloader->wait_for_next_response) { #Second request print $response->code; } You can check this by using an HTTP Header sniffer, like Wireshark
From: mouridis [...] gmail.com
Download (untitled) / with headers
text/plain 401b
In fact, the problem is not the two requests (this is probably due to server redirection and the request is only one if "deltahacker.gr" is used instead of "www.deltahacker.gr"). The problem is that the redirection occurs when calling the next_response or the wait_for_next_response methods. BTW, I'm the same person that committed the bug. I just created a bitcard account to clarify the situation.
Subject: Re: [rt.cpan.org #79285] "next_response" and "wait_for_next_response" methods, both initiate a new HTTP Request
Date: Wed, 29 Aug 2012 17:20:08 +0200
To: bug-HTTP-Async [...] rt.cpan.org
From: Edmund von der Burg <evdb [...] ecclestoad.co.uk>
On 29 August 2012 17:10, Nikos Mouratidis via RT <bug-HTTP-Async@rt.cpan.org> wrote: Show quoted text
> Queue: HTTP-Async > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=79285 > > > In fact, the problem is not the two requests (this is probably due to > server redirection and the request is only one if "deltahacker.gr" is > used instead of "www.deltahacker.gr"). > > The problem is that the redirection occurs when calling the > next_response or the wait_for_next_response methods.
This is not a bug :) When you add the request to the async object the request is sent, but none of the response in inspected (it could take a while to return). Only once you call the next_response or wait_for.... methods does the code look at the response. In this case it sees that it is a 301 or 302 and sends the new request. So yes two requests are sent, but that can't really be avoided. I hope this makes sense? Cheers, Edmund. Show quoted text
> BTW, I'm the same person that committed the bug. I just created a > bitcard account to clarify the situation.
From: mouridis [...] gmail.com
Download (untitled) / with headers
text/plain 1.8k
Thanks for your really *quick* reply! Just wanted to add that if this is the intended behavior then there is a different bug to report: The second HTTP request ignores the header that was set in the initial request. So, for example: my $downloader=HTTP::Async->new; my $request_header=HTTP::Headers->new( User_Agent=>'My-Web-Client/0.01' ); $downloader->add(HTTP::Request->new(GET=>'http://www.deltahacker.gr/',$request_header)); while (my $response=$downloader->wait_for_next_response) { print $response->code; } The above code will result in two HTTP requests. As I see in WireShark, the first request has set the requested user-agent in the HTTP header. The second one (redirected) has empty header. Just reporting - no problem for my needs/use of the module. Thanks! On Wed Aug 29 11:20:45 2012, evdb@ecclestoad.co.uk wrote: Show quoted text
> On 29 August 2012 17:10, Nikos Mouratidis via RT > <bug-HTTP-Async@rt.cpan.org> wrote:
> > Queue: HTTP-Async > > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=79285 > > > > > In fact, the problem is not the two requests (this is probably due to > > server redirection and the request is only one if "deltahacker.gr" is > > used instead of "www.deltahacker.gr"). > > > > The problem is that the redirection occurs when calling the > > next_response or the wait_for_next_response methods.
> > This is not a bug :) > > When you add the request to the async object the request is sent, but > none of the response in inspected (it could take a while to return). > Only once you call the next_response or wait_for.... methods does the > code look at the response. In this case it sees that it is a 301 or > 302 and sends the new request. > > So yes two requests are sent, but that can't really be avoided. > > I hope this makes sense? > > Cheers, > Edmund. > >
> > BTW, I'm the same person that committed the bug. I just created a > > bitcard account to clarify the situation.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.