… | |
… | |
607 | or do { |
607 | or do { |
608 | my $err = "$!"; |
608 | my $err = "$!"; |
609 | %state = (); |
609 | %state = (); |
610 | return $cb->(undef, { @pseudo, Status => 599, Reason => $err }); |
610 | return $cb->(undef, { @pseudo, Status => 599, Reason => $err }); |
611 | }; |
611 | }; |
612 | |
|
|
613 | pop; # free memory, save a tree |
|
|
614 | |
612 | |
615 | return unless delete $state{connect_guard}; |
613 | return unless delete $state{connect_guard}; |
616 | |
614 | |
617 | # get handle |
615 | # get handle |
618 | $state{handle} = new AnyEvent::Handle |
616 | $state{handle} = new AnyEvent::Handle |
… | |
… | |
663 | # status line and headers |
661 | # status line and headers |
664 | $state{read_response} = sub { |
662 | $state{read_response} = sub { |
665 | for ("$_[1]") { |
663 | for ("$_[1]") { |
666 | y/\015//d; # weed out any \015, as they show up in the weirdest of places. |
664 | y/\015//d; # weed out any \015, as they show up in the weirdest of places. |
667 | |
665 | |
668 | /^HTTP\/([0-9\.]+) \s+ ([0-9]{3}) (?: \s+ ([^\012]*) )? \012/igxc |
666 | /^HTTP\/0*([0-9\.]+) \s+ ([0-9]{3}) (?: \s+ ([^\012]*) )? \012/gxci |
669 | or return (%state = (), $cb->(undef, { @pseudo, Status => 599, Reason => "Invalid server response" })); |
667 | or return (%state = (), $cb->(undef, { @pseudo, Status => 599, Reason => "Invalid server response" })); |
670 | |
668 | |
671 | # 100 Continue handling |
669 | # 100 Continue handling |
672 | # should not happen as we don't send expect: 100-continue, |
670 | # should not happen as we don't send expect: 100-continue, |
673 | # but we handle it just in case. |
671 | # but we handle it just in case. |
… | |
… | |
708 | |
706 | |
709 | if ($recurse) { |
707 | if ($recurse) { |
710 | my $status = $hdr{Status}; |
708 | my $status = $hdr{Status}; |
711 | |
709 | |
712 | # industry standard is to redirect POST as GET for |
710 | # industry standard is to redirect POST as GET for |
713 | # 301, 302 and 303, in contrast to http/1.0 and 1.1. |
711 | # 301, 302 and 303, in contrast to HTTP/1.0 and 1.1. |
714 | # also, the UA should ask the user for 301 and 307 and POST, |
712 | # also, the UA should ask the user for 301 and 307 and POST, |
715 | # industry standard seems to be to simply follow. |
713 | # industry standard seems to be to simply follow. |
716 | # we go with the industry standard. |
714 | # we go with the industry standard. |
717 | if ($status == 301 or $status == 302 or $status == 303) { |
715 | if ($status == 301 or $status == 302 or $status == 303) { |
718 | # HTTP/1.1 is unclear on how to mutate the method |
716 | # HTTP/1.1 is unclear on how to mutate the method |
… | |
… | |
722 | $redirect = 1; |
720 | $redirect = 1; |
723 | } |
721 | } |
724 | } |
722 | } |
725 | |
723 | |
726 | my $finish = sub { # ($data, $err_status, $err_reason[, $keepalive]) |
724 | my $finish = sub { # ($data, $err_status, $err_reason[, $keepalive]) |
727 | my $keepalive = pop; |
725 | my $may_keep_alive = $_[3]; |
728 | |
726 | |
729 | $state{handle}->destroy if $state{handle}; |
727 | $state{handle}->destroy if $state{handle}; |
730 | %state = (); |
728 | %state = (); |
731 | |
729 | |
732 | if (defined $_[1]) { |
730 | if (defined $_[1]) { |