Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: george [...] upg-ploiesti.ro
Cc:
AdminCc:

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



Subject: Test fail when no_proxy env var is set or Proxy error code is 503
Hello, On a GNU/Linux machine that uses HTTP Proxy test 6 of t/01_request.t fails for PoCoCl::HTTP version 0.80 ( the request to foo.poe.perl.org). Attached you'll find a patch that fixes the failure on my machine. You may notice that the proxy I use returns error code 503, not 500 nor 502) However I don't know if it's safe to add 503 error code to that conditional or is better to have a conditional that basically passes the test for request 6 in case the HTTP_PROXY env variable is set, regardless of the status code received. Also, 07_proxy.t fails some tests. I modified it (see attached) (mainly using *is* instead of *ok*) so that it spits more useful messages. It turnes out, that the BEGIN block should be like this: for (qw /HTTP_PROXY http_proxy NO_PROXY no_proxy/) { delete $ENV{$_}; } (the file 07_proxy.t.failure.txt is the output of the script when no_proxy env var is set to localhost and it's not deleted in the BEGIN block) -- Dodge this!
Subject: 07_proxy.t.failure.txt
t/07_proxy....1..22 ok 1 - Status Code not ok 2 - Some meaningful description for Test 1 # Failed test 'Some meaningful description for Test 1' # at t/07_proxy.t line 76. # got: 'host' # expected: 'proxy1' ok 3 - Status Code not ok 4 - Some meaningful description for Test 2 # Failed test 'Some meaningful description for Test 2' # at t/07_proxy.t line 92. # got: 'host' # expected: 'proxy2' ok 5 - Status Code not ok 6 - Some meaningful description for Test 3 # Failed test 'Some meaningful description for Test 3' # at t/07_proxy.t line 108. # got: 'host' # expected: 'proxy1' ok 7 - Status Code ok 8 - Some meaningful description for Test 4 ok 9 - Status Code not ok 10 - Some meaningful description for Test 5 # Failed test 'Some meaningful description for Test 5' # at t/07_proxy.t line 141. # got: 'host' # expected: 'proxy1' ok 11 - Status Code not ok 12 - Some meaningful description for Test 6 # Failed test 'Some meaningful description for Test 6' # at t/07_proxy.t line 172. # got: 'host' # expected: 'proxy2' ok 13 - Status Code not ok 14 - Some meaningful description for Test 7 # Failed test 'Some meaningful description for Test 7' # at t/07_proxy.t line 203. # got: 'host' # expected: 'proxy1' ok 15 - Status Code ok 16 - Some meaningful description for Test 8 ok 17 - Cookie test ok 18 - Status Code not ok 19 - Some meaningful description for Test 9 # Failed test 'Some meaningful description for Test 9' # at t/07_proxy.t line 251. # got: 'host' # expected: 'rproxy' # Looks like you planned 22 tests but only ran 19. # Looks like you failed 7 tests of 19 run. dubious Test returned status 7 (wstat 1792, 0x700) DIED. FAILED tests 2, 4, 6, 10, 12, 14, 19-22 Failed 10/22 tests, 54.55% okay Failed Test Stat Wstat Total Fail List of Failed ------------------------------------------------------------------------------- t/07_proxy.t 7 1792 22 13 2 4 6 10 12 14 19-22 Failed 1/1 test scripts. 10/22 subtests failed. Files=1, Tests=22, 1 wallclock secs ( 0.50 cusr + 0.03 csys = 0.53 CPU) Failed 1/1 test programs. 10/22 subtests failed.
Subject: 01_request.diff
--- t/01_request.t.old 2007-01-03 09:50:21.953882000 +0200 +++ t/01_request.t 2007-01-03 10:22:27.334210750 +0200 @@ -183,7 +183,8 @@ ok(1, 'request 5') if $request_path eq ''; ok(1, 'request 4') if $request_path =~ m/projects\/poe/; } - elsif ($http_response->code == 500 or $http_response->code == 502) { + elsif ($http_response->code == 500 or $http_response->code == 502 + or $http_response->code == 503 ) { pass("request 6"); # The next test assumes a particular responding server. # It's bogus is proxying is enabled through the environment.
Subject: 07_proxy.t
#! /usr/bin/perl # $Id: 07_proxy.t 242 2006-03-23 23:46:18Z rcaputo $ # -*- perl -*- # vim: filetype=perl # Contributed by Yuri Karaban. Thank you! use strict; use warnings; use Test::More tests => 22; $SIG{PIPE} = 'IGNORE'; use Socket; use POE; use POE::Session; use POE::Component::Server::TCP; use POE::Component::Client::HTTP; use POE::Filter::HTTPD; use HTTP::Request; use HTTP::Request::Common qw(GET PUT); use HTTP::Response; # We need some control over proxying here. BEGIN { for (qw /HTTP_PROXY http_proxy NO_PROXY no_proxy/) { delete $ENV{$_}; } } POE::Session->create( inline_states => { _start => sub { my $kernel = $_[KERNEL]; $kernel->alias_set('main'); 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} == 4 ) { $_[KERNEL]->yield('begin_tests'); } }, begin_tests => sub { my ( $kernel, $heap ) = @_[ KERNEL, HEAP ]; POE::Component::Client::HTTP->spawn( Alias => 'DefProxy', Proxy => $heap->{proxy1} ); POE::Component::Client::HTTP->spawn( Alias => 'NoProxy', FollowRedirects => 3 ); # Test is default proxy working $kernel->post( DefProxy => request => test1_resp => GET $heap->{host} ); }, test1_resp => sub { my ( $kernel, $heap, $resp_pack ) = @_[ KERNEL, HEAP, ARG1 ]; my $resp = $resp_pack->[0]; if ( is( $resp->code, '200', 'Status Code' ) ) { is( $resp->content, 'proxy1', "Some meaningful description for Test 1" ); } # Test is default proxy override working $kernel->post( DefProxy => request => test2_resp => ( GET $heap->{host} ), undef, undef, $heap->{proxy2} ); }, test2_resp => sub { my ( $kernel, $heap, $resp_pack ) = @_[ KERNEL, HEAP, ARG1 ]; my $resp = $resp_pack->[0]; if ( is( $resp->code, '200', 'Status Code' ) ) { is( $resp->content, 'proxy2', "Some meaningful description for Test 2" ); } # Test per request proxy setting (override with no default proxy) $kernel->post( NoProxy => request => test3_resp => ( GET $heap->{host} ), undef, undef, $heap->{proxy1} ); }, test3_resp => sub { my ( $kernel, $heap, $resp_pack ) = @_[ KERNEL, HEAP, ARG1 ]; my $resp = $resp_pack->[0]; if ( is( $resp->code, '200', 'Status Code' ) ) { is( $resp->content, 'proxy1', "Some meaningful description for Test 3" ); } # Test when no proxy set at all $kernel->post( NoProxy => request => test4_resp => GET $heap->{host} ); }, test4_resp => sub { my ( $kernel, $heap, $resp_pack ) = @_[ KERNEL, HEAP, ARG1 ]; my $resp = $resp_pack->[0]; if ( is( $resp->code, '200', 'Status Code' ) ) { is( $resp->content, 'host', "Some meaningful description for Test 4" ); } # Test is default proxy works for POST $heap->{cookie} = rand; my $req = HTTP::Request->new( POST => $heap->{host}, [ 'Content-Length' => length( $heap->{cookie} ) ], $heap->{cookie} ); $kernel->post( DefProxy => request => test5_resp => $req ); }, test5_resp => sub { my ( $kernel, $heap, $resp_pack ) = @_[ KERNEL, HEAP, ARG1 ]; my $resp = $resp_pack->[0]; if ( is( $resp->code, '200', 'Status Code' ) ) { my ( $name, $content ) = split( ':', $resp->content ); if ( is( $name, 'proxy1', 'Some meaningful description for Test 5' ) ) { is( $content, $heap->{cookie}, 'Cookie test' ); } } # Test is default proxy override works for POST $heap->{cookie} = rand; my $req = HTTP::Request->new( POST => $heap->{host}, [ 'Content-Length' => length( $heap->{cookie} ) ], $heap->{cookie} ); $kernel->post( DefProxy => request => test6_resp => $req, undef, undef, $heap->{proxy2} ); }, test6_resp => sub { my ( $kernel, $heap, $resp_pack ) = @_[ KERNEL, HEAP, ARG1 ]; my $resp = $resp_pack->[0]; if ( is( $resp->code, '200', 'Status Code' ) ) { my ( $name, $content ) = split( ':', $resp->content ); if ( is( $name, 'proxy2', 'Some meaningful description for Test 6' ) ) { is( $content, $heap->{cookie}, 'Cookie test' ); } } # Test is per request proxy works for POST $heap->{cookie} = rand; my $req = HTTP::Request->new( POST => $heap->{host}, [ 'Content-Length' => length( $heap->{cookie} ) ], $heap->{cookie} ); $kernel->post( NoProxy => request => test7_resp => $req, undef, undef, $heap->{proxy1} ); }, test7_resp => sub { my ( $kernel, $heap, $resp_pack ) = @_[ KERNEL, HEAP, ARG1 ]; my $resp = $resp_pack->[0]; if ( is( $resp->code, '200', 'Status Code' ) ) { my ( $name, $content ) = split( ':', $resp->content ); if ( is( $name, 'proxy1', 'Some meaningful description for Test 7' ) ) { is( $content, $heap->{cookie}, 'Cookie test' ); } } # Test is no for POST $heap->{cookie} = rand; my $req = HTTP::Request->new( POST => $heap->{host}, [ 'Content-Length' => length( $heap->{cookie} ) ], $heap->{cookie} ); $kernel->post( NoProxy => request => test8_resp => $req ); }, test8_resp => sub { my ( $kernel, $heap, $resp_pack ) = @_[ KERNEL, HEAP, ARG1 ]; my $resp = $resp_pack->[0]; if ( is( $resp->code, '200', 'Status Code' ) ) { my ( $name, $content ) = split( ':', $resp->content ); if ( is( $name, 'host', 'Some meaningful description for Test 8' ) ) { is( $content, $heap->{cookie}, 'Cookie test' ); } } $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]; if ( is( $resp->code, '200', 'Status Code' ) ) { is( $resp->content, 'rproxy', "Some meaningful description for Test 9" ); } $kernel->post( proxy1 => 'shutdown' ); $kernel->post( proxy2 => 'shutdown' ); $kernel->post( rproxy => 'shutdown' ); $kernel->post( host => 'shutdown' ); } }, heap => { ready_cnt => 0 } ); POE::Kernel->run(); exit 0; sub spawn_http { my $name = shift; POE::Component::Server::TCP->new( Alias => $name, Address => '127.0.0.1', Port => 0, ClientFilter => 'POE::Filter::HTTPD', ClientInput => sub { unshift @_, $name; &handle_request }, Started => sub { my ( $kernel, $heap ) = @_[ KERNEL, HEAP ]; my $port = ( sockaddr_in( $heap->{listener}->getsockname ) )[0]; $kernel->post( 'main', 'set_port', $name, $port ); } ); } 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 ]; if ( $request->isa("HTTP::Response") ) { $heap->{client}->put($request); $kernel->yield("shutdown"); return; } my ( $body, $host ); if ( ( ( $name =~ /^proxy/ && defined( $host = $kernel->alias_resolve('main')->get_heap->{host} ) && $request->uri->canonical ne $host ) || ( $name !~ /^proxy/ && $request->uri->canonical ne '/' ) ) ) { $body = 'url does not match'; } else { $body = $name; } if ( $request->method eq "POST" ) { # passthrough cookie $body .= ':' . $request->content; } my $r = HTTP::Response->new( 200, 'OK', [ 'Connection' => 'Close', 'Content-Type' => 'text/plain' ], $body ); $heap->{client}->put($r) if defined $heap->{client}; $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"); }
Subject: 07_proxy.t.success.txt
t/07_proxy....1..22 ok 1 - Status Code ok 2 - Some meaningful description for Test 1 ok 3 - Status Code ok 4 - Some meaningful description for Test 2 ok 5 - Status Code ok 6 - Some meaningful description for Test 3 ok 7 - Status Code ok 8 - Some meaningful description for Test 4 ok 9 - Status Code ok 10 - Some meaningful description for Test 5 ok 11 - Cookie test ok 12 - Status Code ok 13 - Some meaningful description for Test 6 ok 14 - Cookie test ok 15 - Status Code ok 16 - Some meaningful description for Test 7 ok 17 - Cookie test ok 18 - Status Code ok 19 - Some meaningful description for Test 8 ok 20 - Cookie test ok 21 - Status Code ok 22 - Some meaningful description for Test 9 ok All tests successful. Files=1, Tests=22, 0 wallclock secs ( 0.51 cusr + 0.03 csys = 0.54 CPU)
Fixes applied to what will become 0.82. Thanks again!