AnyEvent-HTTP-MXHR

 view release on metacpan or  search on metacpan

t/001_basic.t  view on Meta::CPAN

use AnyEvent;
use AnyEvent::Handle;
use AnyEvent::Socket;
use AnyEvent::HTTP::MXHR;
use JSON;

test_tcp(
    server => sub {
        my $port = shift;

        my $apoptosis; $apoptosis = AE::timer 60, 0, sub {
            kill TERM => $$;
            undef $apoptosis;
        };

        my $server = tcp_server undef, $port, sub {
            my $fh = shift;
            my $handle = AnyEvent::Handle->new( fh => $fh );

            $handle->push_write(
                "HTTP/1.0 200 ok\r\n" .
                "Content-Type: multipart/mixed; boundary=\"AAABBBCCC\"\r\n\r\n" .
                " " x 2048 . # dummy whitespace required to work with IE
                "\n--AAABBBCCC\n"
            );

            my $i = 1;
            # XXX for some reaason it seems like fork-then-start anyevent
            # has a weird side effect where a watcher's first invocation
            # is executed twice...?
            my $w; $w = AE::timer 1, 1, sub {
                $handle->push_write(
                    "Content-Type: application/json\r\n\r\n" .
                    qq|{ "foo": "bar", "bar": "baz", "seq": $i }| . "\n" .
                    "--AAABBBCCC"
                );
                if ($i++ >= 10) {
                    undef $w;
                }
            };
            my $quit = sub {

t/001_basic.t  view on Meta::CPAN

        my $s; $s = AE::signal TERM => sub {
            undef $s;
            $cv->send;
        };

        $cv->recv;
    },
    client => sub {
        my $port = shift;

        my $apoptosis; $apoptosis = AE::timer 60, 0, sub {
            kill TERM => $$;
            undef $apoptosis;
        };
        my $seq = 1;
        my $guard;
        my $cv = AE::cv { undef $guard };
        my $quit = sub {
            $cv->send();
        };
        $guard = mxhr_get "http://127.0.0.1:$port",



( run in 1.291 second using v1.01-cache-2.11-cpan-49f99fa48dc )