Skip Menu |

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

Report information
The Basics
Id: 14399
Status: resolved
Priority: 0/
Queue: POE-Component-Client-HTTP

People
Owner: Nobody in particular
Requestors: tech [...] askold.not
Cc:
AdminCc:

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



Subject: Proxy settings lost upon redirection
When redirect occurs, POE yielding to itself with new request. When I was adding per request proxy support I did not noticed this. So in this situation per request proxy setting lost and request made as it would without proxy. I made patch which checks if proxy is currently is used and add it to new request. (I will add proxy redirection check to test cases for proxy as soon as I have a time to work on it)
Index: HTTP.pm =================================================================== --- HTTP.pm (revision 211) +++ HTTP.pm (working copy) @@ -469,12 +469,21 @@ # request is in, and only then do the new request, so we # can reuse the connection. DEBUG and warn "Redirected $request_id ", $input->code; + my @proxy; + if ($request->[REQ_USING_PROXY]) { + push @proxy, ('http://' . + $request->host . + ':' . + $request->port . + '/'); + } $kernel->yield ( request => $request, $newrequest, "_redir_".$request->ID, - $request->[REQ_PROG_POSTBACK] + $request->[REQ_PROG_POSTBACK], + @proxy ); return }
Thank you for the patch. I have applied it even without a test case.
[YKAR - Thu Sep 1 06:17:33 2005]: Test case for this situation. (actually patch against 07_proxy.t). Also fix the typo which I made in 07_proxy.t Show quoted text
> When redirect occurs, POE yielding to itself with new request. When I > was adding per request proxy support I did not noticed this. > > So in this situation per request proxy setting lost and request made > as it would without proxy. > > I made patch which checks if proxy is currently is used and add it to > new request. > > (I will add proxy redirection check to test cases for proxy as soon as > I have a time to work on it)
Index: t/07_proxy.t =================================================================== --- t/07_proxy.t (revision 213) +++ t/07_proxy.t (working copy) @@ -8,7 +8,7 @@ use strict; use warnings; -use Test::More tests => 8; +use Test::More tests => 9; $SIG{PIPE} = 'IGNORE'; @@ -33,13 +33,14 @@ spawn_http('proxy1'); spawn_http('proxy2'); spawn_http('host'); + spawn_rproxy(); }, set_port => sub { my ($kernel, $heap, $name, $port) = @_[KERNEL, HEAP, ARG0, ARG1]; $heap->{$name} = "http://127.0.0.1:$port/"; - if (++ $_[HEAP]->{ready_cnt} == 3) { + if (++ $_[HEAP]->{ready_cnt} == 4) { $_[KERNEL]->yield('begin_tests'); } }, @@ -47,7 +48,7 @@ my ($kernel, $heap) = @_[KERNEL, HEAP]; POE::Component::Client::HTTP->spawn(Alias => 'DefProxy', Proxy => $heap->{proxy1}); - POE::Component::Client::HTTP->spawn(Alias => 'NoProxy'); + POE::Component::Client::HTTP->spawn(Alias => 'NoProxy', FollowRedirects => 3); # Test is default proxy working $kernel->post(DefProxy => request => test1_resp => GET $heap->{host}); @@ -153,8 +154,18 @@ fail(); } + $kernel->post(NoProxy => request => test9_resp => (GET 'http://redirect.me/'), + undef, undef, $heap->{rproxy}); + }, + test9_resp => sub { + my ($kernel, $heap, $resp_pack) = @_[KERNEL, HEAP, ARG1]; + my $resp = $resp_pack->[0]; + + ok($resp->is_success && $resp->content eq 'rproxy'); + $kernel->post(proxy1 => 'shutdown'); $kernel->post(proxy2 => 'shutdown'); + $kernel->post(rproxy => 'shutdown'); $kernel->post(host => 'shutdown'); } }, @@ -185,6 +196,23 @@ ); } +sub spawn_rproxy { + POE::Component::Server::TCP->new( + Alias => 'rproxy', + Address => '127.0.0.1', + Port => 0, + ClientFilter => 'POE::Filter::HTTPD', + + ClientInput => \&handle_rproxy_request, + Started => sub { + my ($kernel, $heap) = @_[KERNEL, HEAP]; + my $port = (sockaddr_in($heap->{listener}->getsockname))[0]; + + $kernel->post('main', 'set_port', 'rproxy', $port); + } + ); +} + sub handle_request { my $name = shift; my ($kernel, $heap, $request) = @_[KERNEL, HEAP, ARG0]; @@ -195,13 +223,13 @@ return; } - my ($body, $port); + my ($body, $host); if ( ( ( $name =~ /^proxy/ && - defined($port = $kernel->alias_resolve('main')->get_heap->{http}) && - $request->uri->canonical ne "http://127.0.0.1:$port/" + defined($host = $kernel->alias_resolve('main')->get_heap->{host}) && + $request->uri->canonical ne $host ) || ( @@ -231,3 +259,36 @@ $kernel->yield("shutdown"); } + +sub handle_rproxy_request { + my ($kernel, $heap, $request) = @_[KERNEL, HEAP, ARG0]; + + if ($request->isa("HTTP::Response")) { + $heap->{client}->put($request); + $kernel->yield("shutdown"); + return; + } + + my $host = $kernel->alias_resolve('main')->get_heap->{host}; + my $r; + + if ($request->uri->canonical eq 'http://redirect.me/') { + $r = HTTP::Response->new + (302, + 'Moved', + ['Connection' => 'Close', + 'Content-Type' => 'text/plain', + 'Location' => $host + ]); + } else { + $r = HTTP::Response->new + ( + 200, + 'OK', + ['Connection' => 'Close', 'Content-Type' => 'text/plain'], + $request->uri->canonical eq $host ? 'rproxy' : 'fail' + ); + } + $heap->{client}->put($r) if defined $heap->{client}; + $kernel->yield("shutdown"); +}
Test patch applied. Thank you again!