- if ($state eq 'waitreply') {
- # look at the reply code and decide whether it is a success
- my ($http, $code, $ascii) = $msg =~ m|(HTTP/\d\.\d)\s+(\d+)\s+(.*)|;
- if ($code == 200) {
- # success
- $conn->{_asstate} = 'waitblank';
- } elsif ($code == 302) {
- # redirect
- $conn->{_asstate} = 'waitlocation';
- } else {
- $dxchan->send("$code $ascii");
- $conn->disconnect;
- }
- } elsif ($state eq 'waitlocation') {
- my ($path) = $msg =~ m|Location:\s*(.*)|;
- if ($path) {
- my $newconn;
- my @uri = split m|/+|, $path;
- if ($uri[0] eq 'http:') {
- shift @uri;
- my $host = shift @uri;
- my $newpath = '/' . join('/', @uri);
- $newpath .= '/' if $path =~ m|/$|;
- $newconn = _getpost(ref $conn, $conn->{_assort}, $conn->{caller}, $host, 80, $newpath, @{$conn->{_asargs}});
- } elsif ($path =~ m|^/|) {
- $newconn = _getpost(ref $conn, $conn->{_assort}, $conn->{caller}, $conn->{peerhost}, $conn->{peerport}, $path, @{$conn->{_asargs}});
- }
- if ($newconn) {
- # copy over any elements in $conn that are not in $newconn
- while (my ($k,$v) = each %$conn) {
- dbg("async: $state copying over $k -> \$newconn") if isdbg('async');
- $newconn{$k} = $v unless exists $newconn{$k};
- }
- }
- delete $conn->{on_disconnect};
- $conn->disconnect;
- }
- } elsif ($state eq 'waitblank') {
- unless ($msg) {
- $conn->{_asstate} = 'indata';
- }
- } elsif ($conn->{_asstate} eq 'indata') {