### ----------------------------------------------------
### -- HTTP::Server::Async
### -- Licenses: Artistic-2.0
### -- Authors: Tony O'Dell
### -- File: t/07-chunkedrequestecho.rakutest
### ----------------------------------------------------
use Test;

use lib 't/lib';
use starter;

plan 1;

my $s = srv;

$s.handler(sub ($request, $response) {
    $response.headers<Content-Type> = 'text/plain';
    $response.headers<Connection> = 'close';
    $response.status = 200;
    $response.close($request.data);
});

$s.listen;

my $client = req;
$client.print("POST / HTTP/1.0\r\nTransfer-Encoding: chunked\r\n\r\n");
my @chunks = "4\r\n", "Wiki\r\n", "5\r\n", "pedia\r\n", "e\r\n", " in\r\n\r\nchunks.\r\n", "0\r\n", "\r\n";
for @chunks -> $chunk {
    $client.print($chunk);
    sleep 1;
}

my $data;
while (try $client.recv) -> $str {
    $data ~= $str;
}
$client.close;
ok $data ~~ / "\r\n\r\nWikipedia in\r\n\r\nchunks" /, 'Test for chunked data echo';

# vim: expandtab shiftwidth=4


