1LWP::UserAgent::DNS::HoUsstesr(3Cpomn)tributed Perl DocuLmWePn:t:aUtsieornAgent::DNS::Hosts(3pm)
2
3
4

NAME

6       LWP::UserAgent::DNS::Hosts - Override LWP HTTP/HTTPS request's host
7       like /etc/hosts
8

SYNOPSIS

10         use LWP::UserAgent;
11         use LWP::UserAgent::DNS::Hosts;
12
13         # add entry
14         LWP::UserAgent::DNS::Hosts->register_host(
15             'www.cpan.org' => '127.0.0.1',
16         );
17
18         # add entries
19         LWP::UserAgent::DNS::Hosts->register_hosts(
20             'search.cpan.org' => '192.168.0.100',
21             'pause.perl.org'  => '192.168.0.101',
22         );
23
24         # read hosts file
25         LWP::UserAgent::DNS::Hosts->read_hosts('/path/to/my/hosts');
26
27         LWP::UserAgent::DNS::Hosts->enable_override;
28
29         # override request hosts with peer addr defined above
30         my $ua  = LWP::UserAgent->new;
31         my $res = $ua->get("http://www.cpan.org/");
32         print $res->content; # is same as "http://127.0.0.1/" content
33

DESCRIPTION

35       LWP::UserAgent::DNS::Hosts is a module to override HTTP/HTTPS request
36       peer addresses that uses LWP::UserAgent.
37
38       This module concept was got from LWP::Protocol::PSGI.
39

METHODS

41       register_host($host, $peer_addr)
42             LWP::UserAgent::DNS::Hosts->register_host($host, $peer_addr);
43
44           Registers a pair of hostname and peer ip address.
45
46             # /etc/hosts
47             127.0.0.1    example.com
48
49           equals to:
50
51             LWP::UserAgent::DNS::Hosts->register_hosts('example.com', '127.0.0.1');
52
53       register_hosts(%host_addr_pairs)
54             LWP::UserAgent::DNS::Hosts->register_hosts(
55                 'example.com' => '192.168.0.1',
56                 'example.org' => '192.168.0.2',
57                 ...
58             );
59
60           Registers pairs of hostname and peer ip address.
61
62       read_hosts($file_or_string)
63             LWP::UserAgent::DNS::Hosts->read_hosts('hosts.my');
64
65             LWP::UserAgent::DNS::Hosts->read_hosts(<<'__HOST__');
66                 127.0.0.1      example.com
67                 192.168.0.1    example.net example.org
68             __HOST__
69
70           Registers "/etc/hosts" syntax entries.
71
72       clear_hosts
73           Clears registered pairs.
74
75       enable_override
76             LWP::UserAgent::DNS::Hosts->enable_override;
77             my $guard = LWP::UserAgent::DNS::Hosts->enable_override;
78
79           Enables to override hook.
80
81           If called in a non-void context, returns a Guard object that
82           automatically resets the override when it goes out of context.
83
84       disable_override
85             LWP::UserAgent::DNS::Hosts->disable_override;
86
87           Disables to override hook.
88
89           If you use the guard interface described above, it will be
90           automatically called for you.
91

AUTHOR

93       NAKAGAWA Masaki <masaki@cpan.org>
94

LICENSE

96       This library is free software; you can redistribute it and/or modify it
97       under the same terms as Perl itself.
98

SEE ALSO

100       LWP::Protocol, LWP::Protocol::http, LWP::Protocol::https
101
102
103
104perl v5.36.0                      2023-01-20   LWP::UserAgent::DNS::Hosts(3pm)
Impressum