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.89 by root, Mon Jan 3 00:23:25 2011 UTC vs.
Revision 1.91 by root, Mon Jan 3 01:03:29 2011 UTC

169C<Host:>, C<Content-Length:>, C<Connection:> and C<Cookie:> headers and 169C<Host:>, C<Content-Length:>, C<Connection:> and C<Cookie:> headers and
170will provide defaults at least for C<TE:>, C<Referer:> and C<User-Agent:> 170will provide defaults at least for C<TE:>, C<Referer:> and C<User-Agent:>
171(this can be suppressed by using C<undef> for these headers in which case 171(this can be suppressed by using C<undef> for these headers in which case
172they won't be sent at all). 172they won't be sent at all).
173 173
174You really should provide your own C<User-Agent:> header value that is
175appropriate for your program - I wouldn't be surprised if the default
176AnyEvent string gets blocked by webservers sooner or later.
177
174=item timeout => $seconds 178=item timeout => $seconds
175 179
176The time-out to use for various stages - each connect attempt will reset 180The time-out to use for various stages - each connect attempt will reset
177the timeout, as will read or write activity, i.e. this is not an overall 181the timeout, as will read or write activity, i.e. this is not an overall
178timeout. 182timeout.
329Example: do a HTTP HEAD request on https://www.google.com/, use a 333Example: do a HTTP HEAD request on https://www.google.com/, use a
330timeout of 30 seconds. 334timeout of 30 seconds.
331 335
332 http_request 336 http_request
333 GET => "https://www.google.com", 337 GET => "https://www.google.com",
338 headers => { "user-agent" => "MySearchClient 1.0" },
334 timeout => 30, 339 timeout => 30,
335 sub { 340 sub {
336 my ($body, $hdr) = @_; 341 my ($body, $hdr) = @_;
337 use Data::Dumper; 342 use Data::Dumper;
338 print Dumper $hdr; 343 print Dumper $hdr;
779 } 784 }
780 }; 785 };
781 786
782 $ae_error = 597; # body phase 787 $ae_error = 597; # body phase
783 788
789 my $chunked = $hdr{"transfer-encoding"} =~ /\bchunked\b/i; # not quite correct...
790
784 my $len = $hdr{"content-length"}; 791 my $len = $chunked ? undef : $hdr{"content-length"};
785 792
786 # body handling, many different code paths 793 # body handling, many different code paths
787 # - no body expected 794 # - no body expected
788 # - want_body_handle 795 # - want_body_handle
789 # - te chunked 796 # - te chunked
804 $_[0]->on_error (undef); 811 $_[0]->on_error (undef);
805 $_[0]->on_read (undef); 812 $_[0]->on_read (undef);
806 813
807 $finish->(delete $state{handle}); 814 $finish->(delete $state{handle});
808 815
809 } elsif ($hdr{"transfer-encoding"} =~ /\bchunked\b/i) { 816 } elsif ($chunked) {
810 my $cl = 0; 817 my $cl = 0;
811 my $body = undef; 818 my $body = undef;
812 my $on_body = $arg{on_body} || sub { $body .= shift; 1 }; 819 my $on_body = $arg{on_body} || sub { $body .= shift; 1 };
813 820
814 $state{read_chunk} = sub { 821 $state{read_chunk} = sub {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines