AnyEvent-HTTPD

 view release on metacpan or  search on metacpan

lib/AnyEvent/HTTPD/HTTPConnection.pm  view on Meta::CPAN

      my %p;

      my @res;

      for my $name_para (@pars) {
         my ($name, $par) = split /\s*=\s*/o, $name_para;
         if ($par =~ /^".*"$/o) { $par = _unquote ($par) }
         $p{$name} = $par;
      }

      my ($ctype, $bound) = _content_type_boundary ($hdr->{'content-type'});

      if ($ctype eq 'multipart/mixed') {
         my $parts = $self->decode_multipart ($cont, $bound);
         for my $sp (keys %$parts) {
            for (@{$parts->{$sp}}) {
               push @res, [$p{name}, @$_];
            }
         }

      } else {
         push @res, [$p{name}, $cont, $hdr->{'content-type'}, $p{filename}];
      }

      return @res
   }

   ();
}

sub decode_multipart {
   my ($self, $cont, $boundary) = @_;

lib/AnyEvent/HTTPD/HTTPConnection.pm  view on Meta::CPAN

      }
   }
   ($c, $bound)
}

sub handle_request {
   my ($self, $method, $uri, $hdr, $cont) = @_;

   $self->{keep_alive} = ($hdr->{connection} =~ /keep-alive/io);

   my ($ctype, $bound) = _content_type_boundary ($hdr->{'content-type'});

   if ($ctype eq 'multipart/form-data') {
      $cont = $self->decode_multipart ($cont, $bound);

   } elsif ($ctype =~ /x-www-form-urlencoded/o) {
      $cont = parse_urlencoded ($cont);
   }

   $self->event (request => $method, $uri, $hdr, $cont);
}

t/02_simple_requests.t  view on Meta::CPAN

my $h = AnyEvent::HTTPD->new;

my $req_url;
my $req_hdr;

my ($H, $P);

$h->reg_cb (
   '/test' => sub {
      my ($httpd, $req) = @_;
      $req_hdr = $req->headers->{'content-type'};
      $req->respond ({
         content => [
            'text/plain',
            "Test response\0"
            . $req->client_host . "\0"
            . $req->client_port
         ]
      });
   },
   client_connected => sub {



( run in 2.330 seconds using v1.01-cache-2.11-cpan-524268b4103 )