File: 31_chunked_unexpected_eof.t

package info (click to toggle)
libfurl-perl 3.14-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 660 kB
  • sloc: perl: 2,188; makefile: 5; sh: 1
file content (57 lines) | stat: -rw-r--r-- 1,324 bytes parent folder | download | duplicates (4)
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
53
54
55
56
57
use strict;
use warnings;

use Furl::HTTP;
use IO::Socket::INET;
use Test::More;
use Test::TCP;

my $chunk = "x"x1024;
my @res;
for ( 1..20) {
    push @res, '400', $chunk;
}

test_tcp(
    client => sub {
        my $port = shift;
        my (undef, $code, undef, undef, $body) = Furl::HTTP->new->request(
            method => 'GET',
            host   => '127.0.0.1',
            port   => $port,
            path   => '/',
        );
        is $code, 500, 'code';
        like $body, qr/Unexpected EOF/, 'body';
    },
    server => sub {
        my $port = shift;
        my $listen_sock = IO::Socket::INET->new(
            Listen    => 5,
            LocalHost => '127.0.0.1',
            LocalPort => $port,
            ReuseAddr => 1,
        ) or die $!;
        local $SIG{PIPE} = 'IGNORE';
        while (1) {
            my $sock = $listen_sock->accept
                or next;
            sysread($sock, my $buf, 1048576, 0); # read request
            my $n = syswrite $sock, join(
                "\r\n",
                "HTTP/1.1 200 OK",
                "Content-Type: text/plain",
                "Transfer-Encoding: chunked",
                "Connection: close",
                "",
                @res,
                "5",
            );
            close $sock;
        }
    },
);



done_testing;