… | |
… | |
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 occured), and a hash-ref with |
56 | response headers as second argument. |
56 | response headers 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" "HTTPVersion", "Status" and |
59 | response headers, the "pseudo-headers" (uppercase to avoid clashing |
|
|
60 | with possible response headers) "HTTPVersion", "Status" and "Reason" |
60 | "Reason" contain the three parts of the HTTP Status-Line of the same |
61 | contain the three parts of the HTTP Status-Line of the same name. |
|
|
62 | |
61 | name. The pseudo-header "URL" contains the original URL (which can |
63 | The pseudo-header "URL" contains the actual URL (which can differ |
62 | differ from the requested URL when following redirects). |
64 | from the requested URL when following redirects - for example, you |
|
|
65 | might get an error that your URL scheme is not supported even though |
|
|
66 | your URL is a valid http URL because it redirected to an ftp URL, in |
|
|
67 | which case you can look at the URL pseudo header). |
|
|
68 | |
|
|
69 | The pseudo-header "Redirect" only exists when the request was a |
|
|
70 | result of an internal redirect. In that case it is an array |
|
|
71 | reference with the "($data, $headers)" from the redirect response. |
|
|
72 | Note that this response could in turn be the result of a redirect |
|
|
73 | itself, and "$headers->{Redirect}[1]{Redirect}" will then contain |
|
|
74 | the original response, and so on. |
63 | |
75 | |
64 | If the server sends a header multiple times, then their contents |
76 | If the server sends a header multiple times, then their contents |
65 | will be joined together with a comma (","), as per the HTTP spec. |
77 | will be joined together with a comma (","), as per the HTTP spec. |
66 | |
78 | |
67 | If an internal error occurs, such as not being able to resolve a |
79 | If an internal error occurs, such as not being able to resolve a |
… | |
… | |
95 | and "Referer:" (this can be suppressed by using "undef" for |
107 | and "Referer:" (this can be suppressed by using "undef" for |
96 | these headers in which case they won't be sent at all). |
108 | these headers in which case they won't be sent at all). |
97 | |
109 | |
98 | timeout => $seconds |
110 | timeout => $seconds |
99 | The time-out to use for various stages - each connect attempt |
111 | The time-out to use for various stages - each connect attempt |
100 | will reset the timeout, as will read or write activity. Default |
112 | will reset the timeout, as will read or write activity, i.e. |
|
|
113 | this is not an overall timeout. |
|
|
114 | |
101 | timeout is 5 minutes. |
115 | Default timeout is 5 minutes. |
102 | |
116 | |
103 | proxy => [$host, $port[, $scheme]] or undef |
117 | proxy => [$host, $port[, $scheme]] or undef |
104 | Use the given http proxy for all requests. If not specified, |
118 | Use the given http proxy for all requests. If not specified, |
105 | then the default proxy (as specified by $ENV{http_proxy}) is |
119 | then the default proxy (as specified by $ENV{http_proxy}) is |
106 | used. |
120 | used. |
… | |
… | |
137 | predefined low-security (no verification, highest compatibility) |
151 | predefined low-security (no verification, highest compatibility) |
138 | and high-security (CA and common-name verification) TLS context. |
152 | and high-security (CA and common-name verification) TLS context. |
139 | |
153 | |
140 | The default for this option is "low", which could be interpreted |
154 | The default for this option is "low", which could be interpreted |
141 | as "give me the page, no matter what". |
155 | as "give me the page, no matter what". |
|
|
156 | |
|
|
157 | on_prepare => $callback->($fh) |
|
|
158 | In rare cases you need to "tune" the socket before it is used to |
|
|
159 | connect (for exmaple, to bind it on a given IP address). This |
|
|
160 | parameter overrides the prepare callback passed to |
|
|
161 | "AnyEvent::Socket::tcp_connect" and behaves exactly the same way |
|
|
162 | (e.g. it has to provide a timeout). See the description for the |
|
|
163 | $prepare_cb argument of "AnyEvent::Socket::tcp_connect" for |
|
|
164 | details. |
142 | |
165 | |
143 | on_header => $callback->($headers) |
166 | on_header => $callback->($headers) |
144 | When specified, this callback will be called with the header |
167 | When specified, this callback will be called with the header |
145 | hash as soon as headers have been successfully received from the |
168 | hash as soon as headers have been successfully received from the |
146 | remote server (not on locally-generated errors). |
169 | remote server (not on locally-generated errors). |
… | |
… | |
233 | print "$body\n"; |
256 | print "$body\n"; |
234 | }; |
257 | }; |
235 | |
258 | |
236 | undef $request; |
259 | undef $request; |
237 | |
260 | |
|
|
261 | DNS CACHING |
|
|
262 | AnyEvent::HTTP uses the AnyEvent::Socket::tcp_connect function for the |
|
|
263 | actual connection, which in turn uses AnyEvent::DNS to resolve |
|
|
264 | hostnames. The latter is a simple stub resolver and does no caching on |
|
|
265 | its own. If you want DNS caching, you currently have to provide your own |
|
|
266 | default resolver (by storing a suitable resolver object in |
|
|
267 | $AnyEvent::DNS::RESOLVER). |
|
|
268 | |
238 | GLOBAL FUNCTIONS AND VARIABLES |
269 | GLOBAL FUNCTIONS AND VARIABLES |
239 | AnyEvent::HTTP::set_proxy "proxy-url" |
270 | AnyEvent::HTTP::set_proxy "proxy-url" |
240 | Sets the default proxy server to use. The proxy-url must begin with |
271 | Sets the default proxy server to use. The proxy-url must begin with |
241 | a string of the form "http://host:port" (optionally "https:..."). |
272 | a string of the form "http://host:port" (optionally "https:..."), |
|
|
273 | croaks otherwise. |
|
|
274 | |
|
|
275 | To clear an already-set proxy, use "undef". |
242 | |
276 | |
243 | $AnyEvent::HTTP::MAX_RECURSE |
277 | $AnyEvent::HTTP::MAX_RECURSE |
244 | The default value for the "recurse" request parameter (default: 10). |
278 | The default value for the "recurse" request parameter (default: 10). |
245 | |
279 | |
246 | $AnyEvent::HTTP::USERAGENT |
280 | $AnyEvent::HTTP::USERAGENT |