… | |
… | |
41 | use strict; |
41 | use strict; |
42 | no warnings; |
42 | no warnings; |
43 | |
43 | |
44 | use Errno (); |
44 | use Errno (); |
45 | |
45 | |
46 | use AnyEvent 4.452 (); |
46 | use AnyEvent 5.0 (); |
47 | use AnyEvent::Util (); |
47 | use AnyEvent::Util (); |
48 | use AnyEvent::Socket (); |
48 | use AnyEvent::Socket (); |
49 | use AnyEvent::Handle (); |
49 | use AnyEvent::Handle (); |
50 | |
50 | |
51 | use base Exporter::; |
51 | use base Exporter::; |
52 | |
52 | |
53 | our $VERSION = '1.12'; |
53 | our $VERSION = '1.44'; |
54 | |
54 | |
55 | our @EXPORT = qw(http_get http_post http_head http_request); |
55 | our @EXPORT = qw(http_get http_post http_head http_request); |
56 | |
56 | |
57 | our $USERAGENT = "Mozilla/5.0 (compatible; U; AnyEvent-HTTP/$VERSION; +http://software.schmorp.de/pkg/AnyEvent)"; |
57 | our $USERAGENT = "Mozilla/5.0 (compatible; U; AnyEvent-HTTP/$VERSION; +http://software.schmorp.de/pkg/AnyEvent)"; |
58 | our $MAX_RECURSE = 10; |
58 | our $MAX_RECURSE = 10; |
59 | our $MAX_PERSISTENT = 8; |
59 | our $MAX_PERSISTENT = 8; |
60 | our $PERSISTENT_TIMEOUT = 2; |
60 | our $PERSISTENT_TIMEOUT = 2; |
61 | our $TIMEOUT = 300; |
61 | our $TIMEOUT = 300; |
62 | |
62 | |
63 | # changing these is evil |
63 | # changing these is evil |
64 | our $MAX_PERSISTENT_PER_HOST = 2; |
64 | our $MAX_PERSISTENT_PER_HOST = 0; |
65 | our $MAX_PER_HOST = 4; |
65 | our $MAX_PER_HOST = 4; |
66 | |
66 | |
67 | our $PROXY; |
67 | our $PROXY; |
68 | our $ACTIVE = 0; |
68 | our $ACTIVE = 0; |
69 | |
69 | |
… | |
… | |
94 | When called in void context, nothing is returned. In other contexts, |
94 | When called in void context, nothing is returned. In other contexts, |
95 | C<http_request> returns a "cancellation guard" - you have to keep the |
95 | C<http_request> returns a "cancellation guard" - you have to keep the |
96 | object at least alive until the callback get called. If the object gets |
96 | object at least alive until the callback get called. If the object gets |
97 | destroyed before the callbakc is called, the request will be cancelled. |
97 | destroyed before the callbakc is called, the request will be cancelled. |
98 | |
98 | |
99 | The callback will be called with the response data as first argument |
99 | The callback will be called with the response body data as first argument |
100 | (or C<undef> if it wasn't available due to errors), and a hash-ref with |
100 | (or C<undef> if an error occured), and a hash-ref with response headers as |
101 | response headers as second argument. |
101 | second argument. |
102 | |
102 | |
103 | All the headers in that hash are lowercased. In addition to the response |
103 | All the headers in that hash are lowercased. In addition to the response |
104 | headers, the "pseudo-headers" C<HTTPVersion>, C<Status> and C<Reason> |
104 | headers, the "pseudo-headers" C<HTTPVersion>, C<Status> and C<Reason> |
105 | contain the three parts of the HTTP Status-Line of the same name. The |
105 | contain the three parts of the HTTP Status-Line of the same name. The |
106 | pseudo-header C<URL> contains the original URL (which can differ from the |
106 | pseudo-header C<URL> contains the original URL (which can differ from the |
… | |
… | |
138 | |
138 | |
139 | =item headers => hashref |
139 | =item headers => hashref |
140 | |
140 | |
141 | The request headers to use. Currently, C<http_request> may provide its |
141 | The request headers to use. Currently, C<http_request> may provide its |
142 | own C<Host:>, C<Content-Length:>, C<Connection:> and C<Cookie:> headers |
142 | own C<Host:>, C<Content-Length:>, C<Connection:> and C<Cookie:> headers |
143 | and will provide defaults for C<User-Agent:> and C<Referer:>. |
143 | and will provide defaults for C<User-Agent:> and C<Referer:> (this can be |
|
|
144 | suppressed by using C<undef> for these headers in which case they won't be |
|
|
145 | sent at all). |
144 | |
146 | |
145 | =item timeout => $seconds |
147 | =item timeout => $seconds |
146 | |
148 | |
147 | The time-out to use for various stages - each connect attempt will reset |
149 | The time-out to use for various stages - each connect attempt will reset |
148 | the timeout, as will read or write activity. Default timeout is 5 minutes. |
150 | the timeout, as will read or write activity, i.e. this is not an overall |
|
|
151 | timeout. |
|
|
152 | |
|
|
153 | Default timeout is 5 minutes. |
149 | |
154 | |
150 | =item proxy => [$host, $port[, $scheme]] or undef |
155 | =item proxy => [$host, $port[, $scheme]] or undef |
151 | |
156 | |
152 | Use the given http proxy for all requests. If not specified, then the |
157 | Use the given http proxy for all requests. If not specified, then the |
153 | default proxy (as specified by C<$ENV{http_proxy}>) is used. |
158 | default proxy (as specified by C<$ENV{http_proxy}>) is used. |
154 | |
159 | |
155 | C<$scheme> must be either missing or C<http> for HTTP, or C<https> for |
160 | C<$scheme> must be either missing, C<http> for HTTP or C<https> for |
156 | HTTPS. |
161 | HTTPS. |
157 | |
162 | |
158 | =item body => $string |
163 | =item body => $string |
159 | |
164 | |
160 | The request body, usually empty. Will be-sent as-is (future versions of |
165 | The request body, usually empty. Will be-sent as-is (future versions of |
… | |
… | |
186 | verification) TLS context. |
191 | verification) TLS context. |
187 | |
192 | |
188 | The default for this option is C<low>, which could be interpreted as "give |
193 | The default for this option is C<low>, which could be interpreted as "give |
189 | me the page, no matter what". |
194 | me the page, no matter what". |
190 | |
195 | |
|
|
196 | =item on_prepare => $callback->($fh) |
|
|
197 | |
|
|
198 | In rare cases you need to "tune" the socket before it is used to |
|
|
199 | connect (for exmaple, to bind it on a given IP address). This parameter |
|
|
200 | overrides the prepare callback passed to C<AnyEvent::Socket::tcp_connect> |
|
|
201 | and behaves exactly the same way (e.g. it has to provide a |
|
|
202 | timeout). See the description for the C<$prepare_cb> argument of |
|
|
203 | C<AnyEvent::Socket::tcp_connect> for details. |
|
|
204 | |
191 | =item on_header => $callback->($hdr) |
205 | =item on_header => $callback->($headers) |
192 | |
206 | |
193 | When specified, this callback will be called with the header hash as soon |
207 | When specified, this callback will be called with the header hash as soon |
194 | as headers have been successfully received from the remote server (not on |
208 | as headers have been successfully received from the remote server (not on |
195 | locally-generated errors). |
209 | locally-generated errors). |
196 | |
210 | |
… | |
… | |
200 | |
214 | |
201 | This callback is useful, among other things, to quickly reject unwanted |
215 | This callback is useful, among other things, to quickly reject unwanted |
202 | content, which, if it is supposed to be rare, can be faster than first |
216 | content, which, if it is supposed to be rare, can be faster than first |
203 | doing a C<HEAD> request. |
217 | doing a C<HEAD> request. |
204 | |
218 | |
|
|
219 | Example: cancel the request unless the content-type is "text/html". |
|
|
220 | |
|
|
221 | on_header => sub { |
|
|
222 | $_[0]{"content-type"} =~ /^text\/html\s*(?:;|$)/ |
|
|
223 | }, |
|
|
224 | |
205 | =item on_body => $callback->($data, $hdr) |
225 | =item on_body => $callback->($partial_body, $headers) |
206 | |
226 | |
207 | When specified, all body data will be "filtered" through this callback. |
227 | When specified, all body data will be passed to this callback instead of |
|
|
228 | to the completion callback. The completion callback will get the empty |
|
|
229 | string instead of the body data. |
208 | |
230 | |
209 | The callback will incrementally receive body data, and is supposed to |
231 | It has to return either true (in which case AnyEvent::HTTP will continue), |
210 | return it or a modified version of it (empty strings are valid returns). |
232 | or false, in which case AnyEvent::HTTP will cancel the download (and call |
|
|
233 | the completion callback with an error code of C<598>). |
211 | |
234 | |
212 | If the callback returns C<undef>, then the request will be cancelled. |
235 | This callback is useful when the data is too large to be held in memory |
213 | |
236 | (so the callback writes it to a file) or when only some information should |
214 | This callback is useful when you want to do some processing on the data, |
237 | be extracted, or when the body should be processed incrementally. |
215 | or the data is too large to be held in memory (so the callback writes it |
|
|
216 | to a file and returns the empty string) and so on. |
|
|
217 | |
238 | |
218 | It is usually preferred over doing your own body handling via |
239 | It is usually preferred over doing your own body handling via |
219 | C<want_body_handle>. |
240 | C<want_body_handle>, but in case of streaming APIs, where HTTP is |
|
|
241 | only used to create a connection, C<want_body_handle> is the better |
|
|
242 | alternative, as it allows you to install your own event handler, reducing |
|
|
243 | resource usage. |
220 | |
244 | |
221 | =item want_body_handle => $enable |
245 | =item want_body_handle => $enable |
222 | |
246 | |
223 | When enabled (default is disabled), the behaviour of AnyEvent::HTTP |
247 | When enabled (default is disabled), the behaviour of AnyEvent::HTTP |
224 | changes considerably: after parsing the headers, and instead of |
248 | changes considerably: after parsing the headers, and instead of |
… | |
… | |
236 | This is useful with some push-type services, where, after the initial |
260 | This is useful with some push-type services, where, after the initial |
237 | headers, an interactive protocol is used (typical example would be the |
261 | headers, an interactive protocol is used (typical example would be the |
238 | push-style twitter API which starts a JSON/XML stream). |
262 | push-style twitter API which starts a JSON/XML stream). |
239 | |
263 | |
240 | If you think you need this, first have a look at C<on_body>, to see if |
264 | If you think you need this, first have a look at C<on_body>, to see if |
241 | that doesn'T solve your problem in a better way. |
265 | that doesn't solve your problem in a better way. |
242 | |
266 | |
243 | =back |
267 | =back |
244 | |
268 | |
245 | Example: make a simple HTTP GET request for http://www.nethype.de/ |
269 | Example: make a simple HTTP GET request for http://www.nethype.de/ |
246 | |
270 | |
… | |
… | |
302 | push @{ $CO_SLOT{$_[0]}[1] }, $_[1]; |
326 | push @{ $CO_SLOT{$_[0]}[1] }, $_[1]; |
303 | |
327 | |
304 | _slot_schedule $_[0]; |
328 | _slot_schedule $_[0]; |
305 | } |
329 | } |
306 | |
330 | |
307 | our $qr_nl = qr<\015?\012>; |
331 | our $qr_nl = qr{\015?\012}; |
308 | our $qr_nlnl = qr<\015?\012\015?\012>; |
332 | our $qr_nlnl = qr{(?<![^\012])\015?\012}; |
309 | |
333 | |
310 | our $TLS_CTX_LOW = { cache => 1, sslv2 => 1 }; |
334 | our $TLS_CTX_LOW = { cache => 1, sslv2 => 1 }; |
311 | our $TLS_CTX_HIGH = { cache => 1, verify => 1, verify_peername => "https" }; |
335 | our $TLS_CTX_HIGH = { cache => 1, verify => 1, verify_peername => "https" }; |
312 | |
336 | |
313 | sub http_request($$@) { |
337 | sub http_request($$@) { |
… | |
… | |
347 | $uauthority =~ /^(?: .*\@ )? ([^\@:]+) (?: : (\d+) )?$/x |
371 | $uauthority =~ /^(?: .*\@ )? ([^\@:]+) (?: : (\d+) )?$/x |
348 | or return $cb->(undef, { Status => 599, Reason => "Unparsable URL", URL => $url }); |
372 | or return $cb->(undef, { Status => 599, Reason => "Unparsable URL", URL => $url }); |
349 | |
373 | |
350 | my $uhost = $1; |
374 | my $uhost = $1; |
351 | $uport = $2 if defined $2; |
375 | $uport = $2 if defined $2; |
|
|
376 | |
|
|
377 | $hdr{host} = defined $2 ? "$uhost:$2" : "$uhost" |
|
|
378 | unless exists $hdr{host}; |
352 | |
379 | |
353 | $uhost =~ s/^\[(.*)\]$/$1/; |
380 | $uhost =~ s/^\[(.*)\]$/$1/; |
354 | $upath .= "?$query" if length $query; |
381 | $upath .= "?$query" if length $query; |
355 | |
382 | |
356 | $upath =~ s%^/?%/%; |
383 | $upath =~ s%^/?%/%; |
… | |
… | |
389 | my ($rhost, $rport, $rscheme, $rpath); # request host, port, path |
416 | my ($rhost, $rport, $rscheme, $rpath); # request host, port, path |
390 | |
417 | |
391 | if ($proxy) { |
418 | if ($proxy) { |
392 | ($rpath, $rhost, $rport, $rscheme) = ($url, @$proxy); |
419 | ($rpath, $rhost, $rport, $rscheme) = ($url, @$proxy); |
393 | |
420 | |
|
|
421 | $rscheme = "http" unless defined $rscheme; |
|
|
422 | |
394 | # don't support https requests over https-proxy transport, |
423 | # don't support https requests over https-proxy transport, |
395 | # can't be done with tls as spec'ed, unless you double-encrypt. |
424 | # can't be done with tls as spec'ed, unless you double-encrypt. |
396 | $rscheme = "http" if $uscheme eq "https" && $rscheme eq "https"; |
425 | $rscheme = "http" if $uscheme eq "https" && $rscheme eq "https"; |
397 | } else { |
426 | } else { |
398 | ($rhost, $rport, $rscheme, $rpath) = ($uhost, $uport, $uscheme, $upath); |
427 | ($rhost, $rport, $rscheme, $rpath) = ($uhost, $uport, $uscheme, $upath); |
399 | } |
428 | } |
400 | |
429 | |
401 | $hdr{"user-agent"} ||= $USERAGENT; |
430 | # leave out fragment and query string, just a heuristic |
402 | $hdr{referer} ||= "$uscheme://$uauthority$upath"; # leave out fragment and query string, just a heuristic |
431 | $hdr{referer} ||= "$uscheme://$uauthority$upath" unless exists $hdr{referer}; |
|
|
432 | $hdr{"user-agent"} ||= $USERAGENT unless exists $hdr{"user-agent"}; |
403 | |
433 | |
404 | $hdr{host} = "$uhost:$uport"; |
|
|
405 | $hdr{"content-length"} = length $arg{body}; |
434 | $hdr{"content-length"} = length $arg{body} |
|
|
435 | if length $arg{body} || $method ne "GET"; |
406 | |
436 | |
407 | my %state = (connect_guard => 1); |
437 | my %state = (connect_guard => 1); |
408 | |
438 | |
409 | _get_slot $uhost, sub { |
439 | _get_slot $uhost, sub { |
410 | $state{slot_guard} = shift; |
440 | $state{slot_guard} = shift; |
411 | |
441 | |
412 | return unless $state{connect_guard}; |
442 | return unless $state{connect_guard}; |
413 | |
443 | |
414 | $state{connect_guard} = AnyEvent::Socket::tcp_connect $rhost, $rport, sub { |
444 | $state{connect_guard} = AnyEvent::Socket::tcp_connect $rhost, $rport, sub { |
415 | $state{fh} = shift |
445 | $state{fh} = shift |
|
|
446 | or do { |
|
|
447 | my $err = "$!"; |
|
|
448 | %state = (); |
416 | or return (%state = (), $cb->(undef, { Status => 599, Reason => "$!", URL => $url })); |
449 | return $cb->(undef, { Status => 599, Reason => $err, URL => $url }); |
|
|
450 | }; |
|
|
451 | |
417 | pop; # free memory, save a tree |
452 | pop; # free memory, save a tree |
418 | |
453 | |
419 | return unless delete $state{connect_guard}; |
454 | return unless delete $state{connect_guard}; |
420 | |
455 | |
421 | # get handle |
456 | # get handle |
… | |
… | |
454 | $state{handle}->starttls ("connect") if $uscheme eq "https" && !exists $state{handle}{tls}; |
489 | $state{handle}->starttls ("connect") if $uscheme eq "https" && !exists $state{handle}{tls}; |
455 | |
490 | |
456 | # send request |
491 | # send request |
457 | $state{handle}->push_write ( |
492 | $state{handle}->push_write ( |
458 | "$method $rpath HTTP/1.0\015\012" |
493 | "$method $rpath HTTP/1.0\015\012" |
459 | . (join "", map "\u$_: $hdr{$_}\015\012", keys %hdr) |
494 | . (join "", map "\u$_: $hdr{$_}\015\012", grep defined $hdr{$_}, keys %hdr) |
460 | . "\015\012" |
495 | . "\015\012" |
461 | . (delete $arg{body}) |
496 | . (delete $arg{body}) |
462 | ); |
497 | ); |
|
|
498 | |
|
|
499 | # return if error occured during push_write() |
|
|
500 | return unless %state; |
463 | |
501 | |
464 | %hdr = (); # reduce memory usage, save a kitten |
502 | %hdr = (); # reduce memory usage, save a kitten |
465 | |
503 | |
466 | # status line |
504 | # status line |
467 | $state{handle}->push_read (line => $qr_nl, sub { |
505 | $state{handle}->push_read (line => $qr_nl, sub { |
… | |
… | |
475 | URL => ",$url" |
513 | URL => ",$url" |
476 | ); |
514 | ); |
477 | |
515 | |
478 | # headers, could be optimized a bit |
516 | # headers, could be optimized a bit |
479 | $state{handle}->unshift_read (line => $qr_nlnl, sub { |
517 | $state{handle}->unshift_read (line => $qr_nlnl, sub { |
480 | for ("$_[1]\012") { |
518 | for ("$_[1]") { |
481 | y/\015//d; # weed out any \015, as they show up in the weirdest of places. |
519 | y/\015//d; # weed out any \015, as they show up in the weirdest of places. |
482 | |
520 | |
483 | # things seen, not parsed: |
521 | # things seen, not parsed: |
484 | # p3pP="NON CUR OTPi OUR NOR UNI" |
522 | # p3pP="NON CUR OTPi OUR NOR UNI" |
485 | |
523 | |
486 | $hdr{lc $1} .= ",$2" |
524 | $hdr{lc $1} .= ",$2" |
487 | while /\G |
525 | while /\G |
488 | ([^:\000-\037]+): |
526 | ([^:\000-\037]*): |
489 | [\011\040]* |
527 | [\011\040]* |
490 | ((?: [^\012]+ | \012[\011\040] )*) |
528 | ((?: [^\012]+ | \012[\011\040] )*) |
491 | \012 |
529 | \012 |
492 | /gxc; |
530 | /gxc; |
493 | |
531 | |
… | |
… | |
582 | |
620 | |
583 | redo if /\G\s*,/gc; |
621 | redo if /\G\s*,/gc; |
584 | } |
622 | } |
585 | } |
623 | } |
586 | |
624 | |
587 | if ($redirect) { |
625 | if ($redirect && exists $hdr{location}) { |
588 | # we ignore any errors, as it is very common to receive |
626 | # we ignore any errors, as it is very common to receive |
589 | # Content-Length != 0 but no actual body |
627 | # Content-Length != 0 but no actual body |
590 | # we also access %hdr, as $_[1] might be an erro |
628 | # we also access %hdr, as $_[1] might be an erro |
591 | http_request ($method => $hdr{location}, %arg, recurse => $recurse - 1, $cb); |
629 | http_request ($method => $hdr{location}, %arg, recurse => $recurse - 1, $cb); |
592 | } else { |
630 | } else { |
… | |
… | |
597 | my $len = $hdr{"content-length"}; |
635 | my $len = $hdr{"content-length"}; |
598 | |
636 | |
599 | if (!$redirect && $arg{on_header} && !$arg{on_header}(\%hdr)) { |
637 | if (!$redirect && $arg{on_header} && !$arg{on_header}(\%hdr)) { |
600 | $finish->(undef, { Status => 598, Reason => "Request cancelled by on_header", URL => $url }); |
638 | $finish->(undef, { Status => 598, Reason => "Request cancelled by on_header", URL => $url }); |
601 | } elsif ( |
639 | } elsif ( |
602 | $hdr{Status} =~ /^(?:1..|204|304)$/ |
640 | $hdr{Status} =~ /^(?:1..|[23]04)$/ |
603 | or $method eq "HEAD" |
641 | or $method eq "HEAD" |
604 | or (defined $len && !$len) |
642 | or (defined $len && !$len) |
605 | ) { |
643 | ) { |
606 | # no body |
644 | # no body |
607 | $finish->("", \%hdr); |
645 | $finish->("", \%hdr); |
… | |
… | |
647 | $finish->((substr delete $_[0]{rbuf}, 0, $len, ""), \%hdr) |
685 | $finish->((substr delete $_[0]{rbuf}, 0, $len, ""), \%hdr) |
648 | if $len <= length $_[0]{rbuf}; |
686 | if $len <= length $_[0]{rbuf}; |
649 | }); |
687 | }); |
650 | } else { |
688 | } else { |
651 | $_[0]->on_error (sub { |
689 | $_[0]->on_error (sub { |
652 | $! == Errno::EPIPE |
690 | $! == Errno::EPIPE || !$! |
653 | ? $finish->(delete $_[0]{rbuf}, \%hdr) |
691 | ? $finish->(delete $_[0]{rbuf}, \%hdr) |
654 | : $finish->(undef, { Status => 599, Reason => $_[2], URL => $url }); |
692 | : $finish->(undef, { Status => 599, Reason => $_[2], URL => $url }); |
655 | }); |
693 | }); |
656 | $_[0]->on_read (sub { }); |
694 | $_[0]->on_read (sub { }); |
657 | } |
695 | } |
… | |
… | |
681 | }); |
719 | }); |
682 | } else { |
720 | } else { |
683 | &$handle_actual_request; |
721 | &$handle_actual_request; |
684 | } |
722 | } |
685 | |
723 | |
686 | }, sub { |
724 | }, $arg{on_prepare} || sub { $timeout }; |
687 | $timeout |
|
|
688 | }; |
|
|
689 | }; |
725 | }; |
690 | |
726 | |
691 | defined wantarray && AnyEvent::Util::guard { %state = () } |
727 | defined wantarray && AnyEvent::Util::guard { %state = () } |
692 | } |
728 | } |
693 | |
729 | |
… | |
… | |
714 | =over 4 |
750 | =over 4 |
715 | |
751 | |
716 | =item AnyEvent::HTTP::set_proxy "proxy-url" |
752 | =item AnyEvent::HTTP::set_proxy "proxy-url" |
717 | |
753 | |
718 | Sets the default proxy server to use. The proxy-url must begin with a |
754 | Sets the default proxy server to use. The proxy-url must begin with a |
719 | string of the form C<http://host:port> (optionally C<https:...>). |
755 | string of the form C<http://host:port> (optionally C<https:...>), croaks |
|
|
756 | otherwise. |
|
|
757 | |
|
|
758 | To clear an already-set proxy, use C<undef>. |
720 | |
759 | |
721 | =item $AnyEvent::HTTP::MAX_RECURSE |
760 | =item $AnyEvent::HTTP::MAX_RECURSE |
722 | |
761 | |
723 | The default value for the C<recurse> request parameter (default: C<10>). |
762 | The default value for the C<recurse> request parameter (default: C<10>). |
724 | |
763 | |
725 | =item $AnyEvent::HTTP::USERAGENT |
764 | =item $AnyEvent::HTTP::USERAGENT |
726 | |
765 | |
727 | The default value for the C<User-Agent> header (the default is |
766 | The default value for the C<User-Agent> header (the default is |
728 | C<Mozilla/5.0 (compatible; U; AnyEvent-HTTP/$VERSION; +http://software.schmorp.de/pkg/AnyEvent)>). |
767 | C<Mozilla/5.0 (compatible; U; AnyEvent-HTTP/$VERSION; +http://software.schmorp.de/pkg/AnyEvent)>). |
729 | |
768 | |
730 | =item $AnyEvent::HTTP::MAX_PERSISTENT |
769 | =item $AnyEvent::HTTP::MAX_PER_HOST |
731 | |
770 | |
732 | The maximum number of persistent connections to keep open (default: 8). |
771 | The maximum number of concurrent connections to the same host (identified |
|
|
772 | by the hostname). If the limit is exceeded, then the additional requests |
|
|
773 | are queued until previous connections are closed. |
733 | |
774 | |
734 | Not implemented currently. |
775 | The default value for this is C<4>, and it is highly advisable to not |
735 | |
776 | increase it. |
736 | =item $AnyEvent::HTTP::PERSISTENT_TIMEOUT |
|
|
737 | |
|
|
738 | The maximum time to cache a persistent connection, in seconds (default: 2). |
|
|
739 | |
|
|
740 | Not implemented currently. |
|
|
741 | |
777 | |
742 | =item $AnyEvent::HTTP::ACTIVE |
778 | =item $AnyEvent::HTTP::ACTIVE |
743 | |
779 | |
744 | The number of active connections. This is not the number of currently |
780 | The number of active connections. This is not the number of currently |
745 | running requests, but the number of currently open and non-idle TCP |
781 | running requests, but the number of currently open and non-idle TCP |
… | |
… | |
748 | =back |
784 | =back |
749 | |
785 | |
750 | =cut |
786 | =cut |
751 | |
787 | |
752 | sub set_proxy($) { |
788 | sub set_proxy($) { |
|
|
789 | if (length $_[0]) { |
753 | $PROXY = [$2, $3 || 3128, $1] if $_[0] =~ m%^(https?):// ([^:/]+) (?: : (\d*) )?%ix; |
790 | $_[0] =~ m%^(https?):// ([^:/]+) (?: : (\d*) )?%ix |
|
|
791 | or Carp::croak "$_[0]: invalid proxy URL"; |
|
|
792 | $PROXY = [$2, $3 || 3128, $1] |
|
|
793 | } else { |
|
|
794 | undef $PROXY; |
|
|
795 | } |
754 | } |
796 | } |
755 | |
797 | |
756 | # initialise proxy from environment |
798 | # initialise proxy from environment |
|
|
799 | eval { |
757 | set_proxy $ENV{http_proxy}; |
800 | set_proxy $ENV{http_proxy}; |
|
|
801 | }; |
758 | |
802 | |
759 | =head1 SEE ALSO |
803 | =head1 SEE ALSO |
760 | |
804 | |
761 | L<AnyEvent>. |
805 | L<AnyEvent>. |
762 | |
806 | |