forked from ikegami/perl-LWP-Protocol-AnyEvent-http
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
62 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!perl -w | ||
use strict; | ||
use Test::More; | ||
|
||
use AnyEvent; | ||
use LWP::Protocol::AnyEvent::http; | ||
use LWP::UserAgent; | ||
|
||
# Check whether we can launch the local webserver | ||
if (! eval { | ||
use lib '../inc', 'inc'; | ||
require Test::HTTP::LocalServer; | ||
1; | ||
}) { | ||
plan skip_all => "Couldn't launch test server: $@"; | ||
} else { | ||
plan tests => 4; | ||
}; | ||
|
||
# Launch a timer | ||
my $timer_events = 0; | ||
my $t = AnyEvent->timer( | ||
after => 1, interval => 1, cb => sub { diag "Waiting for reply\n"; $timer_events++ } | ||
); | ||
|
||
my $client = LWP::UserAgent->new(); | ||
|
||
my $server = Test::HTTP::LocalServer->spawn( | ||
#debug => 1, | ||
); | ||
my $url = $server->url; | ||
diag "Retrieving URL: " . $url; | ||
|
||
$client->proxy(http => $url); | ||
|
||
my $fetch_url = "http://no.such.domain"; | ||
my $res = $client->get($fetch_url); | ||
is $res->code, 200, "Got response"; | ||
|
||
is $fetch_url, $res->content, "Sent proxy requet"; | ||
|
||
|
||
undef $t; # stop the timer | ||
|
||
diag "Shutting down server"; | ||
$server->stop; | ||
undef $server; | ||
diag "Done"; | ||
|