Browsermob-Proxy
view release on metacpan or search on metacpan
lib/Browsermob/Proxy.pm view on Meta::CPAN
path => '/',
optional_params => [
'port'
],
description => 'Create a new proxy. Returns a JSON object {"port": your_port} on success"'
},
delete_proxy => {
method => 'DELETE',
path => '/:port',
required_params => [
'port'
],
description => 'Shutdown the proxy and close the port'
},
create_new_har => {
method => 'PUT',
path => '/:port/har',
optional_params => [
'initialPageRef',
'captureHeaders',
'captureContent',
'captureBinaryContent'
],
required_params => [
'port'
],
description => 'creates a new HAR attached to the proxy and returns the HAR content if there was a previous HAR.'
},
retrieve_har => {
method => 'GET',
path => '/:port/har',
required_params => [
'port'
],
description => 'returns the JSON/HAR content representing all the HTTP traffic passed through the proxy'
},
auth_basic => {
method => 'POST',
path => '/:port/auth/basic/:domain',
required_params => [
'port',
'domain'
],
description => 'Sets automatic basic authentication for the specified domain'
},
filter_request => {
method => 'POST',
path => '/:port/filter/request',
required_params => [
'port'
],
description => 'Modify request/payload with javascript'
},
set_timeout => {
method => 'PUT',
path => '/:port/timeout',
required_params => [
'port',
],
optional_params => [
'requestTimeout',
'readTimeout',
'connectionTimeout',
'dnsCacheTimeout'
],
description => 'Handles different proxy timeouts'
}
}
};
has server_addr => (
is => 'rw',
default => sub { '127.0.0.1' }
);
has server_port => (
is => 'rw',
default => sub { 8080 }
);
has port => (
is => 'rw',
lazy => 1,
predicate => 'has_port',
default => sub { '' }
);
has trace => (
is => 'ro',
default => sub { 0 }
);
has mock => (
is => 'rw',
lazy => 1,
predicate => 'has_mock',
default => sub { '' }
);
has _spore => (
is => 'ro',
lazy => 1,
handles => [keys %{ $spec->{methods} }],
builder => sub {
my $self = shift;
my $client = Net::HTTP::Spore->new_from_string(
to_json($self->_spec),
trace => $self->trace
);
$self->_set_middlewares($client, 'json');
return $client;
}
);
around filter_request => sub {
my ($orig, $self, @args) = @_;
my $client = $self->_spore;
lib/Browsermob/Proxy.pm view on Meta::CPAN
);
N.B.: C<firefox_proxy> will AUTOMATICALLY call L</new_har> for you
initiating an unnamed har, unless you pass it something truthy.
=head2 ua_proxy
Generate the proper arguments for the proxy method of
L<LWP::UserAgent>. By default, C<ua_proxy> will initiate a new har for
you automatically, the same as L</selenium_proxy> does. If you want to
initialize the har yourself, pass in something truthy.
my $proxy = Browsermob::Proxy->new;
my $ua = LWP::UserAgent->new;
$ua->proxy($proxy->ua_proxy);
=head2 set_env_proxy
Export to C<%ENV> the properties of this proxy's port. This can be
used in tandem with <LWP::UserAgent/env_proxy>. This will set the
appropriate environment variables, and then your C<$ua> will pick it
up when its C<env_proxy> method is invoked aftewards. As usual, this
will create a new HAR unless you deliberately inhibit it.
$proxy->set_env_proxy;
$ua->env_proxy;
In particular, we set C<http_proxy>, C<https_proxy>, and C<ssl_proxy>
to the appropriate server and port by defining them as keys in C<%ENV>.
=head2 add_basic_auth
Set up automatic Basic authentication for a specified domain. Accepts
as input a HASHREF with the keys C<domain>, C<username>, and
C<password>. For example,
$proxy->add_basic_auth({
domain => '.google.com',
username => 'username',
password => 'password'
});
=head2 set_request_header ( $header, $value )
Takes two STRINGs as arguments. (Unhelpfully) returns a
Net::HTTP::Spore::Response. With this method, we will remove the
specified C<$header> from every request the proxy sees, and replace it
with the C<$header> C<$value> pair that you pass in.
$proxy->set_request_header( 'User-Agent', 'superwoman' );
Under the covers, we are using L</filter_request> with a Javascript
Rhino payload.
=head2 set_timeout ( $timeoutType => $milliseconds )
Set different time outs on the instantiated proxy. You can set
multiple timeouts at once, if you like.
$proxy->timeout(
requestTimeout => 5000,
readTimeout => 6000
);
=over 4
=item *
requestTimeout
Request timeout in milliseconds. A timeout value of -1 is interpreted
as infinite timeout. It equals -1 by default.
=item *
readTimeout
Read timeout is the timeout for waiting for data or, put differently,
a maximum period inactivity between two consecutive data packets. A
timeout value of zero is interpreted as an infinite timeout. It equals
60000 by default.
=item *
connectionTimeout
Determines the timeout in milliseconds until a connection is
established. A timeout value of zero is interpreted as an infinite
timeout. It eqauls 60000 by default.
=item *
dnsCacheTimeout
Sets the maximum length of time that records will be stored in this
Cache. A nonpositive value disables this feature (that is, sets no
limit). It equals 0 by default.
=back
=head2 delete_proxy
Delete the proxy off of the server, shutting down the port. Although
we do try to do this in our DEMOLISH method, we can't do anything if
the C<$proxy> object is kept around during global destruction. If
you're noticing that your BMP server has leftover proxies, you should
start either explicitly C<undef>ing the `$proxy` object or invoking
this method.
# calls ->delete_proxy in our DEMOLISH method, explicitly not
# during global destruction!
undef $proxy;
# manually delete the proxy from the BMP server
$proxy->delete_proxy;
After deleting the proxy, invoking any other method will probably lead
to a C<die> from inside the Net::HTTP::Spore module somewhere.
=head1 SEE ALSO
Please see those modules/websites for more information related to this module.
=over 4
=item *
L<http://bmp.lightbody.net/|http://bmp.lightbody.net/>
=item *
L<https://github.com/lightbody/browsermob-proxy|https://github.com/lightbody/browsermob-proxy>
=item *
L<Browsermob::Server|Browsermob::Server>
=back
=head1 BUGS
Please report any bugs or feature requests on the bugtracker website
https://github.com/gempesaw/Browsermob-Proxy/issues
When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.
=head1 AUTHOR
Daniel Gempesaw <gempesaw@gmail.com>
=head1 COPYRIGHT AND LICENSE
( run in 2.077 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )