ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-HTTP/HTTP.pm
(Generate patch)

Comparing AnyEvent-HTTP/HTTP.pm (file contents):
Revision 1.46 by root, Sat Jul 25 01:29:09 2009 UTC vs.
Revision 1.47 by root, Wed Aug 5 16:07:48 2009 UTC

138 138
139=item headers => hashref 139=item headers => hashref
140 140
141The request headers to use. Currently, C<http_request> may provide its 141The request headers to use. Currently, C<http_request> may provide its
142own C<Host:>, C<Content-Length:>, C<Connection:> and C<Cookie:> headers 142own C<Host:>, C<Content-Length:>, C<Connection:> and C<Cookie:> headers
143and will provide defaults for C<User-Agent:> and C<Referer:>. 143and will provide defaults for C<User-Agent:> and C<Referer:> (this can be
144suppressed by using C<undef> for these headers in which case they won't be
145send at all).
144 146
145=item timeout => $seconds 147=item timeout => $seconds
146 148
147The time-out to use for various stages - each connect attempt will reset 149The time-out to use for various stages - each connect attempt will reset
148the timeout, as will read or write activity. Default timeout is 5 minutes. 150the timeout, as will read or write activity. Default timeout is 5 minutes.
150=item proxy => [$host, $port[, $scheme]] or undef 152=item proxy => [$host, $port[, $scheme]] or undef
151 153
152Use the given http proxy for all requests. If not specified, then the 154Use the given http proxy for all requests. If not specified, then the
153default proxy (as specified by C<$ENV{http_proxy}>) is used. 155default proxy (as specified by C<$ENV{http_proxy}>) is used.
154 156
155C<$scheme> must be either missing or C<http> for HTTP, or C<https> for 157C<$scheme> must be either missing, C<http> for HTTP or C<https> for
156HTTPS. 158HTTPS.
157 159
158=item body => $string 160=item body => $string
159 161
160The request body, usually empty. Will be-sent as-is (future versions of 162The request body, usually empty. Will be-sent as-is (future versions of
401 my ($rhost, $rport, $rscheme, $rpath); # request host, port, path 403 my ($rhost, $rport, $rscheme, $rpath); # request host, port, path
402 404
403 if ($proxy) { 405 if ($proxy) {
404 ($rpath, $rhost, $rport, $rscheme) = ($url, @$proxy); 406 ($rpath, $rhost, $rport, $rscheme) = ($url, @$proxy);
405 407
408 $rscheme = "http" unless defined $rscheme;
409
406 # don't support https requests over https-proxy transport, 410 # don't support https requests over https-proxy transport,
407 # can't be done with tls as spec'ed, unless you double-encrypt. 411 # can't be done with tls as spec'ed, unless you double-encrypt.
408 $rscheme = "http" if $uscheme eq "https" && $rscheme eq "https"; 412 $rscheme = "http" if $uscheme eq "https" && $rscheme eq "https";
409 } else { 413 } else {
410 ($rhost, $rport, $rscheme, $rpath) = ($uhost, $uport, $uscheme, $upath); 414 ($rhost, $rport, $rscheme, $rpath) = ($uhost, $uport, $uscheme, $upath);
411 } 415 }
412 416
413 $hdr{"user-agent"} ||= $USERAGENT; 417 # leave out fragment and query string, just a heuristic
414 $hdr{referer} ||= "$uscheme://$uauthority$upath"; # leave out fragment and query string, just a heuristic 418 $hdr{referer} ||= "$uscheme://$uauthority$upath" unless exists $hdr{referer};
419 $hdr{"user-agent"} ||= $USERAGENT unless exists $hdr{"user-agent"};
415 420
416 $hdr{"content-length"} = length $arg{body}; 421 $hdr{"content-length"} = length $arg{body};
417 422
418 my %state = (connect_guard => 1); 423 my %state = (connect_guard => 1);
419 424
470 $state{handle}->starttls ("connect") if $uscheme eq "https" && !exists $state{handle}{tls}; 475 $state{handle}->starttls ("connect") if $uscheme eq "https" && !exists $state{handle}{tls};
471 476
472 # send request 477 # send request
473 $state{handle}->push_write ( 478 $state{handle}->push_write (
474 "$method $rpath HTTP/1.0\015\012" 479 "$method $rpath HTTP/1.0\015\012"
475 . (join "", map "\u$_: $hdr{$_}\015\012", keys %hdr) 480 . (join "", map "\u$_: $hdr{$_}\015\012", grep defined $hdr{$_}, keys %hdr)
476 . "\015\012" 481 . "\015\012"
477 . (delete $arg{body}) 482 . (delete $arg{body})
478 ); 483 );
479 484
480 %hdr = (); # reduce memory usage, save a kitten 485 %hdr = (); # reduce memory usage, save a kitten
598 603
599 redo if /\G\s*,/gc; 604 redo if /\G\s*,/gc;
600 } 605 }
601 } 606 }
602 607
603 if ($redirect) { 608 if ($redirect && exists $hdr{location}) {
604 # we ignore any errors, as it is very common to receive 609 # we ignore any errors, as it is very common to receive
605 # Content-Length != 0 but no actual body 610 # Content-Length != 0 but no actual body
606 # we also access %hdr, as $_[1] might be an erro 611 # we also access %hdr, as $_[1] might be an erro
607 http_request ($method => $hdr{location}, %arg, recurse => $recurse - 1, $cb); 612 http_request ($method => $hdr{location}, %arg, recurse => $recurse - 1, $cb);
608 } else { 613 } else {
743The default value for the C<User-Agent> header (the default is 748The default value for the C<User-Agent> header (the default is
744C<Mozilla/5.0 (compatible; U; AnyEvent-HTTP/$VERSION; +http://software.schmorp.de/pkg/AnyEvent)>). 749C<Mozilla/5.0 (compatible; U; AnyEvent-HTTP/$VERSION; +http://software.schmorp.de/pkg/AnyEvent)>).
745 750
746=item $AnyEvent::HTTP::MAX_PER_HOST 751=item $AnyEvent::HTTP::MAX_PER_HOST
747 752
748The maximum number of concurrent conenctions to the same host (identified 753The maximum number of concurrent connections to the same host (identified
749by the hostname). If the limit is exceeded, then the additional requests 754by the hostname). If the limit is exceeded, then the additional requests
750are queued until previous connections are closed. 755are queued until previous connections are closed.
751 756
752The default value for this is C<4>, and it is highly advisable to not 757The default value for this is C<4>, and it is highly advisable to not
753increase it. 758increase it.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines