source: main/trunk/greenstone2/perllib/cpan/Mojo/UserAgent/Proxy.pm@ 32205

Last change on this file since 32205 was 32205, checked in by ak19, 6 years ago

First set of commits to do with implementing the new 'paged_html' output option of PDFPlugin that uses using xpdftools' new pdftohtml. So far tested only on Linux (64 bit), but things work there so I'm optimistically committing the changes since they work. 2. Committing the pre-built Linux binaries of XPDFtools for both 32 and 64 bit built by the XPDF group. 2. To use the correct bitness variant of xpdftools, setup.bash now exports the BITNESS env var, consulted by gsConvert.pl. 3. All the perl code changes to do with using xpdf tools' pdftohtml to generate paged_html and feed it in the desired form into GS(3): gsConvert.pl, PDFPlugin.pm and its parent ConvertBinaryPFile.pm have been modified to make it all work. xpdftools' pdftohtml generates a folder containing an html file and a screenshot for each page in a PDF (as well as an index.html linking to each page's html). However, we want a single html file that contains each individual 'page' html's content in a div, and need to do some further HTML style, attribute and structure modifications to massage the xpdftool output to what we want for GS. In order to parse and manipulate the HTML 'DOM' to do this, we're using the Mojo::DOM package that Dr Bainbridge found and which he's compiled up. Mojo::DOM is therefore also committed in this revision. Some further changes and some display fixes are required, but need to check with the others about that.

File size: 2.4 KB
Line 
1package Mojo::UserAgent::Proxy;
2use Mojo::Base -base;
3
4use Mojo::URL;
5
6has [qw(http https not)];
7
8sub detect {
9 my $self = shift;
10 $self->http($ENV{HTTP_PROXY} || $ENV{http_proxy});
11 $self->https($ENV{HTTPS_PROXY} || $ENV{https_proxy});
12 return $self->not([split ',', $ENV{NO_PROXY} || $ENV{no_proxy} || '']);
13}
14
15sub is_needed {
16 !grep { $_[1] =~ /\Q$_\E$/ } @{$_[0]->not || []};
17}
18
19sub prepare {
20 my ($self, $tx) = @_;
21
22 $self->detect if $ENV{MOJO_PROXY};
23 my $req = $tx->req;
24 my $url = $req->url;
25 return unless $self->is_needed($url->host);
26
27 # HTTP proxy
28 my $proto = $url->protocol;
29 my $http = $self->http;
30 $req->proxy(Mojo::URL->new($http)) if $http && $proto eq 'http';
31
32 # HTTPS proxy
33 my $https = $self->https;
34 $req->proxy(Mojo::URL->new($https)) if $https && $proto eq 'https';
35}
36
371;
38
39=encoding utf8
40
41=head1 NAME
42
43Mojo::UserAgent::Proxy - User agent proxy manager
44
45=head1 SYNOPSIS
46
47 use Mojo::UserAgent::Proxy;
48
49 my $proxy = Mojo::UserAgent::Proxy->new;
50 $proxy->detect;
51 say $proxy->http;
52
53=head1 DESCRIPTION
54
55L<Mojo::UserAgent::Proxy> manages proxy servers for L<Mojo::UserAgent>.
56
57=head1 ATTRIBUTES
58
59L<Mojo::UserAgent::Proxy> implements the following attributes.
60
61=head2 http
62
63 my $http = $proxy->http;
64 $proxy = $proxy->http('socks://sri:[email protected]:8080');
65
66Proxy server to use for HTTP and WebSocket requests.
67
68=head2 https
69
70 my $https = $proxy->https;
71 $proxy = $proxy->https('http://sri:[email protected]:8080');
72
73Proxy server to use for HTTPS and WebSocket requests.
74
75=head2 not
76
77 my $not = $proxy->not;
78 $proxy = $proxy->not(['localhost', 'intranet.mojolicious.org']);
79
80Domains that don't require a proxy server to be used.
81
82=head1 METHODS
83
84L<Mojo::UserAgent::Proxy> inherits all methods from L<Mojo::Base> and
85implements the following new ones.
86
87=head2 detect
88
89 $proxy = $proxy->detect;
90
91Check environment variables C<HTTP_PROXY>, C<http_proxy>, C<HTTPS_PROXY>,
92C<https_proxy>, C<NO_PROXY> and C<no_proxy> for proxy information. Automatic
93proxy detection can be enabled with the C<MOJO_PROXY> environment variable.
94
95=head2 is_needed
96
97 my $bool = $proxy->is_needed('intranet.example.com');
98
99Check if request for domain would use a proxy server.
100
101=head2 prepare
102
103 $proxy->prepare(Mojo::Transaction::HTTP->new);
104
105Prepare proxy server information for transaction.
106
107=head1 SEE ALSO
108
109L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
110
111=cut
Note: See TracBrowser for help on using the repository browser.