bumped version.
[AnyEvent-HTTPD.git] / t / 02_simple_requests.t
blobee3db65bbca6238e8105cdf8306fec85513cd89f
1 #!perl
2 use strict;
3 use Test::More tests => 2;
4 use Coro;
5 use AnyEvent::HTTPD;
6 use AnyEvent::Socket;
8 my $c = AnyEvent->condvar;
10 my $h = AnyEvent::HTTPD->new (port => 19090);
12 my $req_url;
13 my $req_hdr;
15 $h->reg_cb (
16    '/test' => sub {
17       my ($httpd, $req) = @_;
18       $req_hdr = $req->{hdr}->{'content-type'};
19       $req->respond ({
20          content => ['text/plain', "Test response"]
21       });
22    },
25 my $hdl;
26 my $buf;
27 tcp_connect '127.0.0.1', 19090, sub {
28    my ($fh) = @_
29       or die "couldn't connect: $!";
31    $hdl =
32       AnyEvent::Handle->new (
33          fh => $fh, on_eof => sub { $c->send ($buf) },
34          on_read => sub {
35             $buf .= $hdl->rbuf;
36             $hdl->rbuf = '';
37          });
38    $hdl->push_write (
39       "GET\040http://localhost:19090/test\040HTTP/1.0\015\012Content-Length:\015\012 10\015\012Content-Type: text/html;\015\012 charSet = \"ISO-8859-1\"; Foo=1\015\012\015\012ABC1234567"
40    );
43 my $r = $c->recv;
45 ok ($r =~ /Test response/m, 'test response ok');
46 ok ($req_hdr =~ /Foo/, 'test header ok');