… | |
… | |
106 | Additional parameters are key-value pairs, and are fully optional. |
106 | Additional parameters are key-value pairs, and are fully optional. |
107 | They include: |
107 | They include: |
108 | |
108 | |
109 | recurse => $count (default: $MAX_RECURSE) |
109 | recurse => $count (default: $MAX_RECURSE) |
110 | Whether to recurse requests or not, e.g. on redirects, |
110 | Whether to recurse requests or not, e.g. on redirects, |
111 | authentication retries and so on, and how often to do so. |
111 | authentication and other retries and so on, and how often to do |
|
|
112 | so. |
112 | |
113 | |
113 | headers => hashref |
114 | headers => hashref |
114 | The request headers to use. Currently, "http_request" may |
115 | The request headers to use. Currently, "http_request" may |
115 | provide its own "Host:", "Content-Length:", "Connection:" and |
116 | provide its own "Host:", "Content-Length:", "Connection:" and |
116 | "Cookie:" headers and will provide defaults at least for "TE:", |
117 | "Cookie:" headers and will provide defaults at least for "TE:", |
… | |
… | |
336 | |
337 | |
337 | Example: do a HTTP HEAD request on https://www.google.com/, use a |
338 | Example: do a HTTP HEAD request on https://www.google.com/, use a |
338 | timeout of 30 seconds. |
339 | timeout of 30 seconds. |
339 | |
340 | |
340 | http_request |
341 | http_request |
341 | GET => "https://www.google.com", |
342 | HEAD => "https://www.google.com", |
342 | headers => { "user-agent" => "MySearchClient 1.0" }, |
343 | headers => { "user-agent" => "MySearchClient 1.0" }, |
343 | timeout => 30, |
344 | timeout => 30, |
344 | sub { |
345 | sub { |
345 | my ($body, $hdr) = @_; |
346 | my ($body, $hdr) = @_; |
346 | use Data::Dumper; |
347 | use Data::Dumper; |
… | |
… | |
428 | |
429 | |
429 | $AnyEvent::HTTP::MAX_RECURSE |
430 | $AnyEvent::HTTP::MAX_RECURSE |
430 | The default value for the "recurse" request parameter (default: 10). |
431 | The default value for the "recurse" request parameter (default: 10). |
431 | |
432 | |
432 | $AnyEvent::HTTP::TIMEOUT |
433 | $AnyEvent::HTTP::TIMEOUT |
433 | The default timeout for conenction operations (default: 300). |
434 | The default timeout for connection operations (default: 300). |
434 | |
435 | |
435 | $AnyEvent::HTTP::USERAGENT |
436 | $AnyEvent::HTTP::USERAGENT |
436 | The default value for the "User-Agent" header (the default is |
437 | The default value for the "User-Agent" header (the default is |
437 | "Mozilla/5.0 (compatible; U; AnyEvent-HTTP/$VERSION; |
438 | "Mozilla/5.0 (compatible; U; AnyEvent-HTTP/$VERSION; |
438 | +http://software.schmorp.de/pkg/AnyEvent)"). |
439 | +http://software.schmorp.de/pkg/AnyEvent)"). |
… | |
… | |
492 | |
493 | |
493 | warn stat $fh; |
494 | warn stat $fh; |
494 | warn -s _; |
495 | warn -s _; |
495 | if (stat $fh and -s _) { |
496 | if (stat $fh and -s _) { |
496 | $ofs = -s _; |
497 | $ofs = -s _; |
497 | warn "-s is ", $ofs;#d# |
498 | warn "-s is ", $ofs; |
498 | $hdr{"if-unmodified-since"} = AnyEvent::HTTP::format_date +(stat _)[9]; |
499 | $hdr{"if-unmodified-since"} = AnyEvent::HTTP::format_date +(stat _)[9]; |
499 | $hdr{"range"} = "bytes=$ofs-"; |
500 | $hdr{"range"} = "bytes=$ofs-"; |
500 | } |
501 | } |
501 | |
502 | |
502 | http_get $url, |
503 | http_get $url, |