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.51 by root, Fri Aug 14 15:21:33 2009 UTC vs.
Revision 1.53 by root, Sat Dec 5 15:37:07 2009 UTC

48use AnyEvent::Socket (); 48use AnyEvent::Socket ();
49use AnyEvent::Handle (); 49use AnyEvent::Handle ();
50 50
51use base Exporter::; 51use base Exporter::;
52 52
53our $VERSION = '1.43'; 53our $VERSION = '1.44';
54 54
55our @EXPORT = qw(http_get http_post http_head http_request); 55our @EXPORT = qw(http_get http_post http_head http_request);
56 56
57our $USERAGENT = "Mozilla/5.0 (compatible; U; AnyEvent-HTTP/$VERSION; +http://software.schmorp.de/pkg/AnyEvent)"; 57our $USERAGENT = "Mozilla/5.0 (compatible; U; AnyEvent-HTTP/$VERSION; +http://software.schmorp.de/pkg/AnyEvent)";
58our $MAX_RECURSE = 10; 58our $MAX_RECURSE = 10;
372 or return $cb->(undef, { Status => 599, Reason => "Unparsable URL", URL => $url }); 372 or return $cb->(undef, { Status => 599, Reason => "Unparsable URL", URL => $url });
373 373
374 my $uhost = $1; 374 my $uhost = $1;
375 $uport = $2 if defined $2; 375 $uport = $2 if defined $2;
376 376
377 $hdr{host} = defined $2 ? "$uhost:$2" : "$uhost"; 377 $hdr{host} = defined $2 ? "$uhost:$2" : "$uhost"
378 unless exists $hdr{host};
378 379
379 $uhost =~ s/^\[(.*)\]$/$1/; 380 $uhost =~ s/^\[(.*)\]$/$1/;
380 $upath .= "?$query" if length $query; 381 $upath .= "?$query" if length $query;
381 382
382 $upath =~ s%^/?%/%; 383 $upath =~ s%^/?%/%;
428 429
429 # leave out fragment and query string, just a heuristic 430 # leave out fragment and query string, just a heuristic
430 $hdr{referer} ||= "$uscheme://$uauthority$upath" unless exists $hdr{referer}; 431 $hdr{referer} ||= "$uscheme://$uauthority$upath" unless exists $hdr{referer};
431 $hdr{"user-agent"} ||= $USERAGENT unless exists $hdr{"user-agent"}; 432 $hdr{"user-agent"} ||= $USERAGENT unless exists $hdr{"user-agent"};
432 433
433 $hdr{"content-length"} = length $arg{body}; 434 $hdr{"content-length"} = length $arg{body}
435 if length $arg{body} || $method ne "GET";
434 436
435 my %state = (connect_guard => 1); 437 my %state = (connect_guard => 1);
436 438
437 _get_slot $uhost, sub { 439 _get_slot $uhost, sub {
438 $state{slot_guard} = shift; 440 $state{slot_guard} = shift;
745=over 4 747=over 4
746 748
747=item AnyEvent::HTTP::set_proxy "proxy-url" 749=item AnyEvent::HTTP::set_proxy "proxy-url"
748 750
749Sets the default proxy server to use. The proxy-url must begin with a 751Sets the default proxy server to use. The proxy-url must begin with a
750string of the form C<http://host:port> (optionally C<https:...>). 752string of the form C<http://host:port> (optionally C<https:...>), croaks
753otherwise.
754
755To clear an already-set proxy, use C<undef>.
751 756
752=item $AnyEvent::HTTP::MAX_RECURSE 757=item $AnyEvent::HTTP::MAX_RECURSE
753 758
754The default value for the C<recurse> request parameter (default: C<10>). 759The default value for the C<recurse> request parameter (default: C<10>).
755 760
776=back 781=back
777 782
778=cut 783=cut
779 784
780sub set_proxy($) { 785sub set_proxy($) {
786 if (length $_[0]) {
781 $PROXY = [$2, $3 || 3128, $1] if $_[0] =~ m%^(https?):// ([^:/]+) (?: : (\d*) )?%ix; 787 $_[0] =~ m%^(https?):// ([^:/]+) (?: : (\d*) )?%ix
788 or Carp::croak "$_[0]: invalid proxy URL";
789 $PROXY = [$2, $3 || 3128, $1]
790 } else {
791 undef $PROXY;
792 }
782} 793}
783 794
784# initialise proxy from environment 795# initialise proxy from environment
796eval {
785set_proxy $ENV{http_proxy}; 797 set_proxy $ENV{http_proxy};
798};
786 799
787=head1 SEE ALSO 800=head1 SEE ALSO
788 801
789L<AnyEvent>. 802L<AnyEvent>.
790 803

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines