forked from ikegami/perl-LWP-Protocol-AnyEvent-http
/
07_proxy.t
49 lines (37 loc) · 955 Bytes
/
07_proxy.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!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";