.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "AnyEvent::Connector 3pm" .TH AnyEvent::Connector 3pm "2019-10-09" "perl v5.30.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" AnyEvent::Connector \- tcp_connect with transparent proxy handling .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use AnyEvent::Connector; \& \& ## Specify the proxy setting explicitly. \& my $c = AnyEvent::Connector\->new( \& proxy => \*(Aqhttp://proxy.example.com:8080\*(Aq, \& no_proxy => [\*(Aqlocalhost\*(Aq, \*(Aqyour\-internal\-domain.net\*(Aq] \& ); \& \& ## Proxy setting from "http_proxy" and "no_proxy" environment variables. \& my $cenv = AnyEvent::Connector\->new( \& env_proxy => "http", \& ); \& \& ## Same API as AnyEvent::Socket::tcp_connect \& my $guard = $c\->tcp_connect( \& "target.hogehoge.org", 80, \& sub { \& ## connect callback \& my ($fh ,$host, $port, $retry) = @_; \& ...; \& }, \& sub { \& ## prepare calback \& my ($fh) = @_; \& ...; \& } \& ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" AnyEvent::Connector object has \f(CW\*(C`tcp_connect\*(C'\fR method compatible with that from AnyEvent::Socket, and it handles proxy settings transparently. .SH "CLASS METHODS" .IX Header "CLASS METHODS" .ie n .SS "$conn = AnyEvent::Connector\->new(%args)" .el .SS "\f(CW$conn\fP = AnyEvent::Connector\->new(%args)" .IX Subsection "$conn = AnyEvent::Connector->new(%args)" The constructor. .PP Fields in \f(CW%args\fR are: .ie n .IP """proxy"" => \s-1STR\s0 (optional)" 4 .el .IP "\f(CWproxy\fR => \s-1STR\s0 (optional)" 4 .IX Item "proxy => STR (optional)" String of proxy \s-1URL.\s0 Currently only \f(CW\*(C`http\*(C'\fR proxy is supported. .Sp If both \f(CW\*(C`proxy\*(C'\fR and \f(CW\*(C`env_proxy\*(C'\fR are not specified, the \f(CW$conn\fR will directly connect to the destination host. .Sp If both \f(CW\*(C`proxy\*(C'\fR and \f(CW\*(C`env_proxy\*(C'\fR are specified, setting by \f(CW\*(C`proxy\*(C'\fR is used. .Sp Setting empty string to \f(CW\*(C`proxy\*(C'\fR disables the proxy setting done by \f(CW\*(C`env_proxy\*(C'\fR option. .ie n .IP """no_proxy"" => \s-1STR\s0 or \s-1ARRAYREF\s0 of \s-1STR\s0 (optional)" 4 .el .IP "\f(CWno_proxy\fR => \s-1STR\s0 or \s-1ARRAYREF\s0 of \s-1STR\s0 (optional)" 4 .IX Item "no_proxy => STR or ARRAYREF of STR (optional)" String or array-ref of strings of domain names, to which the \f(CW$conn\fR will directly connect. .Sp If both \f(CW\*(C`no_proxy\*(C'\fR and \f(CW\*(C`env_proxy\*(C'\fR are specified, setting by \f(CW\*(C`no_proxy\*(C'\fR is used. .Sp Setting empty string or empty array-ref to \f(CW\*(C`no_proxy\*(C'\fR disables the no_proxy setting done by \f(CW\*(C`env_proxy\*(C'\fR option. .ie n .IP """env_proxy"" => \s-1STR\s0 (optional)" 4 .el .IP "\f(CWenv_proxy\fR => \s-1STR\s0 (optional)" 4 .IX Item "env_proxy => STR (optional)" String of protocol specifier. If specified, proxy settings for that protocol are loaded from environment variables, and \f(CW$conn\fR is created. .Sp For example, if \f(CW"http"\fR is specified, \f(CW\*(C`http_proxy\*(C'\fR (or \&\f(CW\*(C`HTTP_PROXY\*(C'\fR) and \f(CW\*(C`no_proxy\*(C'\fR (or \f(CW\*(C`NO_PROXY\*(C'\fR) environment variables are used to set \f(CW\*(C`proxy\*(C'\fR and \f(CW\*(C`no_proxy\*(C'\fR options, respectively. .Sp \&\f(CW\*(C`proxy\*(C'\fR and \f(CW\*(C`no_proxy\*(C'\fR options have precedence over \f(CW\*(C`env_proxy\*(C'\fR option. .SH "OBJECT METHOD" .IX Header "OBJECT METHOD" .ie n .SS "$guard = $conn\->tcp_connect($host, $port, $connect_cb, $prepare_cb)" .el .SS "\f(CW$guard\fP = \f(CW$conn\fP\->tcp_connect($host, \f(CW$port\fP, \f(CW$connect_cb\fP, \f(CW$prepare_cb\fP)" .IX Subsection "$guard = $conn->tcp_connect($host, $port, $connect_cb, $prepare_cb)" Make a (possibly proxied) \s-1TCP\s0 connection to the given \f(CW$host\fR and \&\f(CW$port\fR. .PP If \f(CW\*(C`$conn\->proxy_for($host, $port)\*(C'\fR returns \f(CW\*(C`undef\*(C'\fR, the behavior of this method is exactly the same as \f(CW\*(C`tcp_connect\*(C'\fR function from AnyEvent::Socket. .PP If \f(CW\*(C`$conn\->proxy_for($host, $port)\*(C'\fR returns a proxy \s-1URL,\s0 it behaves in the following way. .IP "\(bu" 4 It connects to the proxy, and tells the proxy to connect to the final destination, \f(CW$host\fR and \f(CW$port\fR. .IP "\(bu" 4 It runs \f(CW$connect_cb\fR after the connection to the proxy \s-1AND\s0 (hopefully) the connection between the proxy and the final destination are both established. .Sp .Vb 1 \& $connect_cb\->($cb_fh, $cb_host, $cb_port, $cb_retry) .Ve .Sp \&\f(CW$cb_fh\fR is the filehandle to the proxy. \f(CW$cb_host\fR and \f(CW$cb_port\fR are the hostname and port of the proxy. .IP "\(bu" 4 If the \s-1TCP\s0 connection to the proxy is established but the connection to the final destination fails for some reason, \f(CW$connect_cb\fR is called with no argument passed (just as the original \f(CW\*(C`tcp_connect\*(C'\fR does). .IP "\(bu" 4 If given, it runs \f(CW$prepare_cb\fR before it starts connecting to the proxy. .ie n .SS "$proxy = $conn\->proxy_for($host, $port)" .el .SS "\f(CW$proxy\fP = \f(CW$conn\fP\->proxy_for($host, \f(CW$port\fP)" .IX Subsection "$proxy = $conn->proxy_for($host, $port)" If \f(CW$conn\fR uses a proxy to connect to the given \f(CW$host\fR and \&\f(CW$port\fR, it returns the string of the proxy \s-1URL.\s0 Otherwise, it returns \f(CW\*(C`undef\*(C'\fR. .SH "SEE ALSO" .IX Header "SEE ALSO" .IP "\(bu" 4 AnyEvent::Socket .IP "\(bu" 4 AnyEvent::HTTP \- it has \f(CW\*(C`tcp_connect\*(C'\fR option to implement proxy connection. You can use AnyEvent::Connector for it. .SH "REPOSITORY" .IX Header "REPOSITORY" .SH "BUGS AND FEATURE REQUESTS" .IX Header "BUGS AND FEATURE REQUESTS" Please report bugs and feature requests to my Github issues . .PP Although I prefer Github, non-Github users can use \s-1CPAN RT\s0 . Please send email to \f(CW\*(C`bug\-AnyEvent\-Connector at rt.cpan.org\*(C'\fR to report bugs if you do not have \s-1CPAN RT\s0 account. .SH "AUTHOR" .IX Header "AUTHOR" Toshio Ito, \f(CW\*(C`\*(C'\fR .SH "LICENSE AND COPYRIGHT" .IX Header "LICENSE AND COPYRIGHT" Copyright 2018 Toshio Ito. .PP This program is free software; you can redistribute it and/or modify it under the terms of either: the \s-1GNU\s0 General Public License as published by the Free Software Foundation; or the Artistic License. .PP See for more information.