Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 52 lines (39 sloc) 1.14 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
use strict;

use Test::More;

{
    package Starman::Server;

    # Override the sysread method enabling it to read a stream of packages
    # from an arrayref instead of an file handle:
    use subs 'sysread';

    *Starman::Server::sysread = sub {
        if (ref $_[0] eq "ARRAY") {
            die "EWOULDBLOCK\n" unless @{ $_[0] };

            $_[1] = shift @{ $_[0] };
            return length $_[1];
        }

        return CORE::sysread($_[0], $_[1], $_[2]);
    };

}

use Starman::Server;

my $server = {
    server => {
        client => [
            "3\015\012foo\015\012", # Full chunk
            "3\015\012bar", # Chunk missing terminating HTTP newline
            "\015\012", # ... and then the termination
            "0\015\012", # Empty chunk to mark end of stream
        ],
    }
};

my $env = {
    HTTP_TRANSFER_ENCODING => 'chunked',
};

my $blocked;
eval {
    Starman::Server::_prepare_env( $server, $env );
    1;
} or do {
    $blocked = 1 if $@ =~ /^EWOULDBLOCK$/;
};

ok( !$blocked, "Reading chunked encoding does not block on well-placed package borders" );

done_testing;
Something went wrong with that request. Please try again.