]> Dogcows Code - chaz/p5-HTTP-AnyUA/blob - t/40-middleware-content-length.t
change an instance of "and" to "&&"
[chaz/p5-HTTP-AnyUA] / t / 40-middleware-content-length.t
1 #!perl
2
3 use warnings;
4 use strict;
5
6 use lib 't/lib';
7
8 use HTTP::AnyUA;
9 use Test::More tests => 3;
10
11 HTTP::AnyUA->register_backend(Mock => '+MockBackend');
12
13 my $any_ua = HTTP::AnyUA->new(ua => 'Mock');
14 my $backend = $any_ua->backend;
15
16 $any_ua->apply_middleware('ContentLength');
17
18 my $url = 'http://acme.tld/';
19 my $content = "hello world\n";
20
21 $any_ua->post($url, {content => $content});
22 my $cl = ($backend->requests)[-1][2]{headers}{'content-length'};
23 is $cl, length($content), 'content-length is set correctly with string content';
24
25 $any_ua->post($url);
26 $cl = ($backend->requests)[-1][2]{headers}{'content-length'};
27 is $cl, undef, 'content-length is not set with no content';
28
29 my $chunk = 0;
30 my @chunk = ('some ', 'document');
31 my $code = sub { return $chunk[$chunk++] };
32
33 $any_ua->post($url, {content => $code});
34 $cl = ($backend->requests)[-1][2]{headers}{'content-length'};
35 is $cl, undef, 'content-length is not set with coderef content';
36
This page took 0.030688 seconds and 4 git commands to generate.