File: proxy_request.t

package info (click to toggle)
libwww-perl 6.78-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,008 kB
  • sloc: perl: 4,148; makefile: 10; sh: 6
file content (84 lines) | stat: -rw-r--r-- 1,758 bytes parent folder | download
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use strict;
use warnings;
use Test::More;

use LWP::UserAgent ();

# Prevent environment from interfering with test:
delete $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME};
delete $ENV{HTTPS_CA_FILE};
delete $ENV{HTTPS_CA_DIR};
delete $ENV{PERL_LWP_SSL_CA_FILE};
delete $ENV{PERL_LWP_SSL_CA_PATH};
delete $ENV{PERL_LWP_ENV_PROXY};

my $ua = LWP::UserAgent->new;
$ua->default_header( 'Content-Type' => 'application/json' );
$ua->proxy( http => "loopback:" );
$ua->agent("foo/0.1");

is(
    $ua->get("http://www.example.org")->content,
    <<EOT , "request gets proxied" );
GET http://www.example.org
User-Agent: foo/0.1
Content-Type: application/json

EOT

$ua->no_proxy('ample.org');
is_deeply(
    $ua->{no_proxy}, ['ample.org'],
    "no_proxy with partial domain got set"
);

is(
    $ua->get("http://www.example.org")->content,
    <<EOT , "request still gets proxied" );
GET http://www.example.org
User-Agent: foo/0.1
Content-Type: application/json

EOT

$ua->no_proxy();
is_deeply(
    $ua->{no_proxy}, [],
    "no_proxy was cleared"
);
$ua->no_proxy('example.org');
is_deeply(
    $ua->{no_proxy}, ['example.org'],
    "no_proxy with base domain got set"
);

isnt(
    $ua->get("http://www.example.org")->content,
    <<EOT , "request does not get proxied" );
GET http://www.example.org
User-Agent: foo/0.1
Content-Type: application/json

EOT

$ua->no_proxy();
is_deeply(
    $ua->{no_proxy}, [],
    "no_proxy was cleared"
);
$ua->no_proxy('.example.org');
is_deeply(
    $ua->{no_proxy}, ['.example.org'],
    "no_proxy with dot-prefixed base domain got set"
);

isnt(
    $ua->get("http://www.example.org")->content,
    <<EOT , "request does not get proxied" );
GET http://www.example.org
User-Agent: foo/0.1
Content-Type: application/json

EOT

done_testing;