Implemented in attached patch. With example.
Will be in next release.
--
Paul Evans
=== modified file 'examples/GET.pl'
--- examples/GET.pl 2011-12-25 00:13:37 +0000
+++ examples/GET.pl 2012-02-29 21:45:31 +0000
@@ -5,12 +5,21 @@
use URI;
+use Getopt::Long;
use IO::Async::Loop;
use Net::Async::HTTP;
+GetOptions(
+ 'local-host=s' => \my $LOCAL_HOST,
+ 'local-port=i' => \my $LOCAL_PORT,
+) or exit 1;
+
my $loop = IO::Async::Loop->new;
-my $ua = Net::Async::HTTP->new;
+my $ua = Net::Async::HTTP->new(
+ local_host => $LOCAL_HOST,
+ local_port => $LOCAL_PORT,
+);
$loop->add( $ua );
$ua->do_request(
=== modified file 'lib/Net/Async/HTTP.pm'
--- lib/Net/Async/HTTP.pm 2012-02-29 21:12:08 +0000
+++ lib/Net/Async/HTTP.pm 2012-02-29 21:45:31 +0000
@@ -120,6 +120,18 @@
Optional. If false, disables HTTP/1.1-style request pipelining.
+=item local_host => STRING
+
+=item local_port => INT
+
+=item local_addrs => ARRAY
+
+=item local_addr => HASH or ARRAY
+
+Optional. Parameters to pass on to the C<connect> method used to connect
+sockets to HTTP servers. Sets the local socket address to C<bind()> to. For
+more detail, see the documentation in L<IO::Async::Connector>.
+
=back
=cut
@@ -129,7 +141,8 @@
my $self = shift;
my %params = @_;
- foreach (qw( user_agent max_redirects timeout proxy_host proxy_port cookie_jar pipeline )) {
+ foreach (qw( user_agent max_redirects timeout proxy_host proxy_port cookie_jar pipeline
+ local_host local_port local_addrs local_addr )) {
$self->{$_} = delete $params{$_} if exists $params{$_};
}
@@ -203,6 +216,8 @@
},
%args,
+
+ ( map { defined $self->{$_} ? ( $_ => $self->{$_} ) : () } qw( local_host local_port local_addrs local_addr ) ),
);
$conn->run_when_ready( $on_ready, $on_error );