… | |
… | |
745 | =over 4 |
745 | =over 4 |
746 | |
746 | |
747 | =item AnyEvent::HTTP::set_proxy "proxy-url" |
747 | =item AnyEvent::HTTP::set_proxy "proxy-url" |
748 | |
748 | |
749 | Sets the default proxy server to use. The proxy-url must begin with a |
749 | Sets the default proxy server to use. The proxy-url must begin with a |
750 | string of the form C<http://host:port> (optionally C<https:...>). |
750 | string of the form C<http://host:port> (optionally C<https:...>), croaks |
|
|
751 | otherwise. |
|
|
752 | |
|
|
753 | To clear an already-set proxy, use C<undef>. |
751 | |
754 | |
752 | =item $AnyEvent::HTTP::MAX_RECURSE |
755 | =item $AnyEvent::HTTP::MAX_RECURSE |
753 | |
756 | |
754 | The default value for the C<recurse> request parameter (default: C<10>). |
757 | The default value for the C<recurse> request parameter (default: C<10>). |
755 | |
758 | |
… | |
… | |
776 | =back |
779 | =back |
777 | |
780 | |
778 | =cut |
781 | =cut |
779 | |
782 | |
780 | sub set_proxy($) { |
783 | sub set_proxy($) { |
|
|
784 | if (length $_[0]) { |
781 | $PROXY = [$2, $3 || 3128, $1] if $_[0] =~ m%^(https?):// ([^:/]+) (?: : (\d*) )?%ix; |
785 | $_[0] =~ m%^(https?):// ([^:/]+) (?: : (\d*) )?%ix |
|
|
786 | or Carp::croak "$_[0]: invalid proxy URL"; |
|
|
787 | $PROXY = [$2, $3 || 3128, $1] |
|
|
788 | } else { |
|
|
789 | undef $PROXY; |
|
|
790 | } |
782 | } |
791 | } |
783 | |
792 | |
784 | # initialise proxy from environment |
793 | # initialise proxy from environment |
|
|
794 | eval { |
785 | set_proxy $ENV{http_proxy}; |
795 | set_proxy $ENV{http_proxy}; |
|
|
796 | }; |
786 | |
797 | |
787 | =head1 SEE ALSO |
798 | =head1 SEE ALSO |
788 | |
799 | |
789 | L<AnyEvent>. |
800 | L<AnyEvent>. |
790 | |
801 | |