… | |
… | |
3 | AnyEvent::HTTP - simple but non-blocking HTTP/HTTPS client |
3 | AnyEvent::HTTP - simple but non-blocking HTTP/HTTPS client |
4 | |
4 | |
5 | =head1 SYNOPSIS |
5 | =head1 SYNOPSIS |
6 | |
6 | |
7 | use AnyEvent::HTTP; |
7 | use AnyEvent::HTTP; |
|
|
8 | |
|
|
9 | http_get "http://www.nethype.de/", sub { print $_[1] }; |
|
|
10 | |
|
|
11 | # ... do something else here |
8 | |
12 | |
9 | =head1 DESCRIPTION |
13 | =head1 DESCRIPTION |
10 | |
14 | |
11 | This module is an L<AnyEvent> user, you need to make sure that you use and |
15 | This module is an L<AnyEvent> user, you need to make sure that you use and |
12 | run a supported event loop. |
16 | run a supported event loop. |
… | |
… | |
44 | use AnyEvent::Socket (); |
48 | use AnyEvent::Socket (); |
45 | use AnyEvent::Handle (); |
49 | use AnyEvent::Handle (); |
46 | |
50 | |
47 | use base Exporter::; |
51 | use base Exporter::; |
48 | |
52 | |
49 | our $VERSION = '1.0'; |
53 | our $VERSION = '1.01'; |
50 | |
54 | |
51 | our @EXPORT = qw(http_get http_request); |
55 | our @EXPORT = qw(http_get http_post http_head http_request); |
52 | |
56 | |
53 | our $USERAGENT = "Mozilla/5.0 (compatible; AnyEvent::HTTP/$VERSION; +http://software.schmorp.de/pkg/AnyEvent)"; |
57 | our $USERAGENT = "Mozilla/5.0 (compatible; AnyEvent::HTTP/$VERSION; +http://software.schmorp.de/pkg/AnyEvent)"; |
54 | our $MAX_RECURSE = 10; |
58 | our $MAX_RECURSE = 10; |
55 | our $MAX_PERSISTENT = 8; |
59 | our $MAX_PERSISTENT = 8; |
56 | our $PERSISTENT_TIMEOUT = 2; |
60 | our $PERSISTENT_TIMEOUT = 2; |
… | |
… | |
214 | push @{ $CO_SLOT{$_[0]}[1] }, $_[1]; |
218 | push @{ $CO_SLOT{$_[0]}[1] }, $_[1]; |
215 | |
219 | |
216 | _slot_schedule $_[0]; |
220 | _slot_schedule $_[0]; |
217 | } |
221 | } |
218 | |
222 | |
219 | sub http_request($$$;@) { |
223 | sub http_request($$@) { |
220 | my $cb = pop; |
224 | my $cb = pop; |
221 | my ($method, $url, %arg) = @_; |
225 | my ($method, $url, %arg) = @_; |
222 | |
226 | |
223 | my %hdr; |
227 | my %hdr; |
224 | |
228 | |
… | |
… | |
447 | }; |
451 | }; |
448 | |
452 | |
449 | defined wantarray && AnyEvent::Util::guard { %state = () } |
453 | defined wantarray && AnyEvent::Util::guard { %state = () } |
450 | } |
454 | } |
451 | |
455 | |
452 | sub http_get($$;@) { |
456 | sub http_get($@) { |
453 | unshift @_, "GET"; |
457 | unshift @_, "GET"; |
454 | &http_request |
458 | &http_request |
455 | } |
459 | } |
456 | |
460 | |
457 | sub http_head($$;@) { |
461 | sub http_head($@) { |
458 | unshift @_, "HEAD"; |
462 | unshift @_, "HEAD"; |
459 | &http_request |
463 | &http_request |
460 | } |
464 | } |
461 | |
465 | |
462 | sub http_post($$$;@) { |
466 | sub http_post($$@) { |
463 | unshift @_, "POST", "body"; |
467 | unshift @_, "POST", "body"; |
464 | &http_request |
468 | &http_request |
465 | } |
469 | } |
466 | |
470 | |
467 | =back |
471 | =back |