… | |
… | |
48 | use AnyEvent::Socket (); |
48 | use AnyEvent::Socket (); |
49 | use AnyEvent::Handle (); |
49 | use AnyEvent::Handle (); |
50 | |
50 | |
51 | use base Exporter::; |
51 | use base Exporter::; |
52 | |
52 | |
53 | our $VERSION = '1.05'; |
53 | our $VERSION = '1.11'; |
54 | |
54 | |
55 | our @EXPORT = qw(http_get http_post http_head http_request); |
55 | our @EXPORT = qw(http_get http_post http_head http_request); |
56 | |
56 | |
57 | 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)"; |
58 | our $MAX_RECURSE = 10; |
58 | our $MAX_RECURSE = 10; |
… | |
… | |
426 | |
426 | |
427 | substr $_, 0, 1, "" |
427 | substr $_, 0, 1, "" |
428 | for values %hdr; |
428 | for values %hdr; |
429 | |
429 | |
430 | my $finish = sub { |
430 | my $finish = sub { |
431 | # TODO: use destroy method, when/if available |
|
|
432 | #$state{handle}->destroy; |
431 | $state{handle}->destroy; |
433 | $state{handle}->on_eof (undef); |
|
|
434 | $state{handle}->on_error (undef); |
|
|
435 | %state = (); |
432 | %state = (); |
436 | |
433 | |
437 | # set-cookie processing |
434 | # set-cookie processing |
438 | if ($arg{cookie_jar}) { |
435 | if ($arg{cookie_jar}) { |
439 | for ($hdr{"set-cookie"}) { |
436 | for ($hdr{"set-cookie"}) { |
… | |
… | |
528 | }); |
525 | }); |
529 | } else { |
526 | } else { |
530 | # too bad, need to read until we get an error or EOF, |
527 | # too bad, need to read until we get an error or EOF, |
531 | # no way to detect winged data. |
528 | # no way to detect winged data. |
532 | $_[0]->on_error (sub { |
529 | $_[0]->on_error (sub { |
|
|
530 | # delete ought to be more efficient, as we would have to make |
|
|
531 | # a copy otherwise as $_[0] gets destroyed. |
533 | $finish->($_[0]{rbuf}, \%hdr); |
532 | $finish->(delete $_[0]{rbuf}, \%hdr); |
534 | }); |
533 | }); |
535 | $_[0]->on_eof (undef); |
534 | $_[0]->on_eof (undef); |
536 | $_[0]->on_read (sub { }); |
535 | $_[0]->on_read (sub { }); |
537 | } |
536 | } |
538 | } |
537 | } |
… | |
… | |
642 | =head1 AUTHOR |
641 | =head1 AUTHOR |
643 | |
642 | |
644 | Marc Lehmann <schmorp@schmorp.de> |
643 | Marc Lehmann <schmorp@schmorp.de> |
645 | http://home.schmorp.de/ |
644 | http://home.schmorp.de/ |
646 | |
645 | |
|
|
646 | With many thanks to Дмитрий Шалашов, who provided countless |
|
|
647 | testcases and bugreports. |
|
|
648 | |
647 | =cut |
649 | =cut |
648 | |
650 | |
649 | 1 |
651 | 1 |
650 | |
652 | |