… | |
… | |
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 | |
… | |
… | |
354 | $uauthority =~ /^(?: .*\@ )? ([^\@:]+) (?: : (\d+) )?$/x |
354 | $uauthority =~ /^(?: .*\@ )? ([^\@:]+) (?: : (\d+) )?$/x |
355 | or return $cb->(undef, { Status => 599, Reason => "Unparsable URL", URL => $url }); |
355 | or return $cb->(undef, { Status => 599, Reason => "Unparsable URL", URL => $url }); |
356 | |
356 | |
357 | my $uhost = $1; |
357 | my $uhost = $1; |
358 | $uport = $2 if defined $2; |
358 | $uport = $2 if defined $2; |
|
|
359 | |
|
|
360 | $hdr{host} = defined $2 ? "$uhost:$2" : "$uhost"; |
359 | |
361 | |
360 | $uhost =~ s/^\[(.*)\]$/$1/; |
362 | $uhost =~ s/^\[(.*)\]$/$1/; |
361 | $upath .= "?$query" if length $query; |
363 | $upath .= "?$query" if length $query; |
362 | |
364 | |
363 | $upath =~ s%^/?%/%; |
365 | $upath =~ s%^/?%/%; |
… | |
… | |
406 | } |
408 | } |
407 | |
409 | |
408 | $hdr{"user-agent"} ||= $USERAGENT; |
410 | $hdr{"user-agent"} ||= $USERAGENT; |
409 | $hdr{referer} ||= "$uscheme://$uauthority$upath"; # leave out fragment and query string, just a heuristic |
411 | $hdr{referer} ||= "$uscheme://$uauthority$upath"; # leave out fragment and query string, just a heuristic |
410 | |
412 | |
411 | $hdr{host} = "$uhost:$uport"; |
|
|
412 | $hdr{"content-length"} = length $arg{body}; |
413 | $hdr{"content-length"} = length $arg{body}; |
413 | |
414 | |
414 | my %state = (connect_guard => 1); |
415 | my %state = (connect_guard => 1); |
415 | |
416 | |
416 | _get_slot $uhost, sub { |
417 | _get_slot $uhost, sub { |
… | |
… | |
490 | # things seen, not parsed: |
491 | # things seen, not parsed: |
491 | # p3pP="NON CUR OTPi OUR NOR UNI" |
492 | # p3pP="NON CUR OTPi OUR NOR UNI" |
492 | |
493 | |
493 | $hdr{lc $1} .= ",$2" |
494 | $hdr{lc $1} .= ",$2" |
494 | while /\G |
495 | while /\G |
495 | ([^:\000-\037]+): |
496 | ([^:\000-\037]*): |
496 | [\011\040]* |
497 | [\011\040]* |
497 | ((?: [^\012]+ | \012[\011\040] )*) |
498 | ((?: [^\012]+ | \012[\011\040] )*) |
498 | \012 |
499 | \012 |
499 | /gxc; |
500 | /gxc; |
500 | |
501 | |
… | |
… | |
654 | $finish->((substr delete $_[0]{rbuf}, 0, $len, ""), \%hdr) |
655 | $finish->((substr delete $_[0]{rbuf}, 0, $len, ""), \%hdr) |
655 | if $len <= length $_[0]{rbuf}; |
656 | if $len <= length $_[0]{rbuf}; |
656 | }); |
657 | }); |
657 | } else { |
658 | } else { |
658 | $_[0]->on_error (sub { |
659 | $_[0]->on_error (sub { |
659 | $! == Errno::EPIPE |
660 | $! == Errno::EPIPE || !$! |
660 | ? $finish->(delete $_[0]{rbuf}, \%hdr) |
661 | ? $finish->(delete $_[0]{rbuf}, \%hdr) |
661 | : $finish->(undef, { Status => 599, Reason => $_[2], URL => $url }); |
662 | : $finish->(undef, { Status => 599, Reason => $_[2], URL => $url }); |
662 | }); |
663 | }); |
663 | $_[0]->on_read (sub { }); |
664 | $_[0]->on_read (sub { }); |
664 | } |
665 | } |
… | |
… | |
732 | =item $AnyEvent::HTTP::USERAGENT |
733 | =item $AnyEvent::HTTP::USERAGENT |
733 | |
734 | |
734 | The default value for the C<User-Agent> header (the default is |
735 | The default value for the C<User-Agent> header (the default is |
735 | C<Mozilla/5.0 (compatible; U; AnyEvent-HTTP/$VERSION; +http://software.schmorp.de/pkg/AnyEvent)>). |
736 | C<Mozilla/5.0 (compatible; U; AnyEvent-HTTP/$VERSION; +http://software.schmorp.de/pkg/AnyEvent)>). |
736 | |
737 | |
737 | =item $AnyEvent::HTTP::MAX_PERSISTENT |
738 | =item $AnyEvent::HTTP::MAX_PER_HOST |
738 | |
739 | |
739 | The maximum number of persistent connections to keep open (default: 8). |
740 | The maximum number of concurrent conenctions to the same host (identified |
|
|
741 | by the hostname). If the limit is exceeded, then the additional requests |
|
|
742 | are queued until previous connections are closed. |
740 | |
743 | |
741 | Not implemented currently. |
744 | The default value for this is C<4>, and it is highly advisable to not |
742 | |
745 | increase it. |
743 | =item $AnyEvent::HTTP::PERSISTENT_TIMEOUT |
|
|
744 | |
|
|
745 | The maximum time to cache a persistent connection, in seconds (default: 2). |
|
|
746 | |
|
|
747 | Not implemented currently. |
|
|
748 | |
746 | |
749 | =item $AnyEvent::HTTP::ACTIVE |
747 | =item $AnyEvent::HTTP::ACTIVE |
750 | |
748 | |
751 | The number of active connections. This is not the number of currently |
749 | The number of active connections. This is not the number of currently |
752 | running requests, but the number of currently open and non-idle TCP |
750 | running requests, but the number of currently open and non-idle TCP |