… | |
… | |
52 | =item http_get $url, key => value..., $cb->($data, $headers) |
52 | =item http_get $url, key => value..., $cb->($data, $headers) |
53 | |
53 | |
54 | Executes an HTTP-GET request. See the http_request function for details on |
54 | Executes an HTTP-GET request. See the http_request function for details on |
55 | additional parameters. |
55 | additional parameters. |
56 | |
56 | |
|
|
57 | =item http_head $url, key => value..., $cb->($data, $headers) |
|
|
58 | |
|
|
59 | Executes an HTTP-HEAD request. See the http_request function for details on |
|
|
60 | additional parameters. |
|
|
61 | |
57 | =item http_get $url, $body, key => value..., $cb->($data, $headers) |
62 | =item http_post $url, $body, key => value..., $cb->($data, $headers) |
58 | |
63 | |
59 | Executes an HTTP-POST request with a requets body of C<$bod>. See the |
64 | Executes an HTTP-POST request with a requets body of C<$bod>. See the |
60 | http_request function for details on additional parameters. |
65 | http_request function for details on additional parameters. |
61 | |
66 | |
62 | =item http_request $method => $url, key => value..., $cb->($data, $headers) |
67 | =item http_request $method => $url, key => value..., $cb->($data, $headers) |
… | |
… | |
241 | } |
246 | } |
242 | |
247 | |
243 | substr $_, 0, 1, "" |
248 | substr $_, 0, 1, "" |
244 | for values %hdr; |
249 | for values %hdr; |
245 | |
250 | |
246 | if ($method ne "HEAD") { |
251 | if ($method eq "HEAD") { |
|
|
252 | %state = (); |
|
|
253 | $cb->(undef, \%hdr); |
|
|
254 | } else { |
247 | if (exists $hdr{"content-length"}) { |
255 | if (exists $hdr{"content-length"}) { |
248 | $_[0]->unshift_read (chunk => $hdr{"content-length"}, sub { |
256 | $_[0]->unshift_read (chunk => $hdr{"content-length"}, sub { |
249 | # could cache persistent connection now |
257 | # could cache persistent connection now |
250 | if ($hdr{connection} =~ /\bkeep-alive\b/i) { |
258 | if ($hdr{connection} =~ /\bkeep-alive\b/i) { |
251 | # but we don't, due to misdesigns, this is annoyingly complex |
259 | # but we don't, due to misdesigns, this is annoyingly complex |
… | |
… | |
277 | sub http_get($$;@) { |
285 | sub http_get($$;@) { |
278 | unshift @_, "GET"; |
286 | unshift @_, "GET"; |
279 | &http_request |
287 | &http_request |
280 | } |
288 | } |
281 | |
289 | |
|
|
290 | sub http_head($$;@) { |
|
|
291 | unshift @_, "HEAD"; |
|
|
292 | &http_request |
|
|
293 | } |
|
|
294 | |
282 | sub http_post($$$;@) { |
295 | sub http_post($$$;@) { |
283 | unshift @_, "POST", "body"; |
296 | unshift @_, "POST", "body"; |
284 | &http_request |
297 | &http_request |
285 | } |
298 | } |
286 | |
299 | |