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

Comparing AnyEvent-HTTP/README (file contents):
Revision 1.24 by root, Wed Nov 14 22:22:24 2012 UTC vs.
Revision 1.25 by root, Sun Jun 8 23:33:28 2014 UTC

50 object at least alive until the callback get called. If the object 50 object at least alive until the callback get called. If the object
51 gets destroyed before the callback is called, the request will be 51 gets destroyed before the callback is called, the request will be
52 cancelled. 52 cancelled.
53 53
54 The callback will be called with the response body data as first 54 The callback will be called with the response body data as first
55 argument (or "undef" if an error occured), and a hash-ref with 55 argument (or "undef" if an error occurred), and a hash-ref with
56 response headers (and trailers) as second argument. 56 response headers (and trailers) as second argument.
57 57
58 All the headers in that hash are lowercased. In addition to the 58 All the headers in that hash are lowercased. In addition to the
59 response headers, the "pseudo-headers" (uppercase to avoid clashing 59 response headers, the "pseudo-headers" (uppercase to avoid clashing
60 with possible response headers) "HTTPVersion", "Status" and "Reason" 60 with possible response headers) "HTTPVersion", "Status" and "Reason"
82 If an internal error occurs, such as not being able to resolve a 82 If an internal error occurs, such as not being able to resolve a
83 hostname, then $data will be "undef", "$headers->{Status}" will be 83 hostname, then $data will be "undef", "$headers->{Status}" will be
84 590-599 and the "Reason" pseudo-header will contain an error 84 590-599 and the "Reason" pseudo-header will contain an error
85 message. Currently the following status codes are used: 85 message. Currently the following status codes are used:
86 86
87 595 - errors during connection etsbalishment, proxy handshake. 87 595 - errors during connection establishment, proxy handshake.
88 596 - errors during TLS negotiation, request sending and header 88 596 - errors during TLS negotiation, request sending and header
89 processing. 89 processing.
90 597 - errors during body receiving or processing. 90 597 - errors during body receiving or processing.
91 598 - user aborted request via "on_header" or "on_body". 91 598 - user aborted request via "on_header" or "on_body".
92 599 - other, usually nonretryable, errors (garbled URL etc.). 92 599 - other, usually nonretryable, errors (garbled URL etc.).
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 and other retries and so on, and how often to do 111 authentication and other retries and so on, and how often to do
112 so. 112 so.
113
114 Only redirects to http and https URLs are supported. While most
115 common redirection forms are handled entirely within this
116 module, some require the use of the optional URI module. If it
117 is required but missing, then the request will fail with an
118 error.
113 119
114 headers => hashref 120 headers => hashref
115 The request headers to use. Currently, "http_request" may 121 The request headers to use. Currently, "http_request" may
116 provide its own "Host:", "Content-Length:", "Connection:" and 122 provide its own "Host:", "Content-Length:", "Connection:" and
117 "Cookie:" headers and will provide defaults at least for "TE:", 123 "Cookie:" headers and will provide defaults at least for "TE:",
189 object storing your state data, or the TLS context) - only 195 object storing your state data, or the TLS context) - only
190 connections using the same unique ID will be reused. 196 connections using the same unique ID will be reused.
191 197
192 on_prepare => $callback->($fh) 198 on_prepare => $callback->($fh)
193 In rare cases you need to "tune" the socket before it is used to 199 In rare cases you need to "tune" the socket before it is used to
194 connect (for exmaple, to bind it on a given IP address). This 200 connect (for example, to bind it on a given IP address). This
195 parameter overrides the prepare callback passed to 201 parameter overrides the prepare callback passed to
196 "AnyEvent::Socket::tcp_connect" and behaves exactly the same way 202 "AnyEvent::Socket::tcp_connect" and behaves exactly the same way
197 (e.g. it has to provide a timeout). See the description for the 203 (e.g. it has to provide a timeout). See the description for the
198 $prepare_cb argument of "AnyEvent::Socket::tcp_connect" for 204 $prepare_cb argument of "AnyEvent::Socket::tcp_connect" for
199 details. 205 details.
372 Sets the default proxy server to use. The proxy-url must begin with 378 Sets the default proxy server to use. The proxy-url must begin with
373 a string of the form "http://host:port", croaks otherwise. 379 a string of the form "http://host:port", croaks otherwise.
374 380
375 To clear an already-set proxy, use "undef". 381 To clear an already-set proxy, use "undef".
376 382
377 When AnyEvent::HTTP is laoded for the first time it will query the 383 When AnyEvent::HTTP is loaded for the first time it will query the
378 default proxy from the operating system, currently by looking at 384 default proxy from the operating system, currently by looking at
379 "$ENV{http_proxy"}. 385 "$ENV{http_proxy"}.
380 386
381 AnyEvent::HTTP::cookie_jar_expire $jar[, $session_end] 387 AnyEvent::HTTP::cookie_jar_expire $jar[, $session_end]
382 Remove all cookies from the cookie jar that have been expired. If 388 Remove all cookies from the cookie jar that have been expired. If
384 cookies. 390 cookies.
385 391
386 You should call this function (with a true $session_end) before you 392 You should call this function (with a true $session_end) before you
387 save cookies to disk, and you should call this function after 393 save cookies to disk, and you should call this function after
388 loading them again. If you have a long-running program you can 394 loading them again. If you have a long-running program you can
389 additonally call this function from time to time. 395 additionally call this function from time to time.
390 396
391 A cookie jar is initially an empty hash-reference that is managed by 397 A cookie jar is initially an empty hash-reference that is managed by
392 this module. It's format is subject to change, but currently it is 398 this module. It's format is subject to change, but currently it is
393 like this: 399 like this:
394 400
395 The key "version" has to contain 1, otherwise the hash gets emptied. 401 The key "version" has to contain 1, otherwise the hash gets emptied.
396 All other keys are hostnames or IP addresses pointing to 402 All other keys are hostnames or IP addresses pointing to
397 hash-references. The key for these inner hash references is the 403 hash-references. The key for these inner hash references is the
398 server path for which this cookie is meant, and the values are again 404 server path for which this cookie is meant, and the values are again
399 hash-references. The keys of those hash-references is the cookie 405 hash-references. Each key of those hash-references is a cookie name,
400 name, and the value, you guessed it, is another hash-reference, this 406 and the value, you guessed it, is another hash-reference, this time
401 time with the key-value pairs from the cookie, except for "expires" 407 with the key-value pairs from the cookie, except for "expires" and
402 and "max-age", which have been replaced by a "_expires" key that 408 "max-age", which have been replaced by a "_expires" key that
403 contains the cookie expiry timestamp. 409 contains the cookie expiry timestamp. Session cookies are indicated
410 by not having an "_expires" key.
404 411
405 Here is an example of a cookie jar with a single cookie, so you have 412 Here is an example of a cookie jar with a single cookie, so you have
406 a chance of understanding the above paragraph: 413 a chance of understanding the above paragraph:
407 414
408 { 415 {
447 454
448 The default value for this is 4, and it is highly advisable to not 455 The default value for this is 4, and it is highly advisable to not
449 increase it much. 456 increase it much.
450 457
451 For comparison: the RFC's recommend 4 non-persistent or 2 persistent 458 For comparison: the RFC's recommend 4 non-persistent or 2 persistent
452 connections, older browsers used 2, newers (such as firefox 3) 459 connections, older browsers used 2, newer ones (such as firefox 3)
453 typically use 6, and Opera uses 8 because like, they have the 460 typically use 6, and Opera uses 8 because like, they have the
454 fastest browser and give a shit for everybody else on the planet. 461 fastest browser and give a shit for everybody else on the planet.
455 462
456 $AnyEvent::HTTP::PERSISTENT_TIMEOUT 463 $AnyEvent::HTTP::PERSISTENT_TIMEOUT
457 The time after which idle persistent conenctions get closed by 464 The time after which idle persistent connections get closed by
458 AnyEvent::HTTP (default: 3). 465 AnyEvent::HTTP (default: 3).
459 466
460 $AnyEvent::HTTP::ACTIVE 467 $AnyEvent::HTTP::ACTIVE
461 The number of active connections. This is not the number of 468 The number of active connections. This is not the number of
462 currently running requests, but the number of currently open and 469 currently running requests, but the number of currently open and
463 non-idle TCP connections. This number can be useful for 470 non-idle TCP connections. This number can be useful for
464 load-leveling. 471 load-leveling.
465 472
466 SHOWCASE 473 SHOWCASE
467 This section contaisn some more elaborate "real-world" examples or code 474 This section contains some more elaborate "real-world" examples or code
468 snippets. 475 snippets.
469 476
470 HTTP/1.1 FILE DOWNLOAD 477 HTTP/1.1 FILE DOWNLOAD
471 Downloading files with HTTP can be quite tricky, especially when 478 Downloading files with HTTP can be quite tricky, especially when
472 something goes wrong and you want to resume. 479 something goes wrong and you want to resume.
475 last modified time to check for file content changes, and works with 482 last modified time to check for file content changes, and works with
476 many HTTP/1.0 servers as well, and usually falls back to a complete 483 many HTTP/1.0 servers as well, and usually falls back to a complete
477 re-download on older servers. 484 re-download on older servers.
478 485
479 It calls the completion callback with either "undef", which means a 486 It calls the completion callback with either "undef", which means a
480 nonretryable error occured, 0 when the download was partial and should 487 nonretryable error occurred, 0 when the download was partial and should
481 be retried, and 1 if it was successful. 488 be retried, and 1 if it was successful.
482 489
483 use AnyEvent::HTTP; 490 use AnyEvent::HTTP;
484 491
485 sub download($$$) { 492 sub download($$$) {
623 630
624AUTHOR 631AUTHOR
625 Marc Lehmann <schmorp@schmorp.de> 632 Marc Lehmann <schmorp@schmorp.de>
626 http://home.schmorp.de/ 633 http://home.schmorp.de/
627 634
628 With many thanks to Дмитрий Шалашов, who provided 635 With many thanks to Дмитрий Шалашов, who provided countless testcases
629 countless testcases and bugreports. 636 and bugreports.
630 637

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines