initial commit
[chaz/p5-HTTP-AnyUA] / t / 13-head.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;
10 use Util qw(:server :test :ua);
11
12 my $server = start_server('t/app.psgi');
13
14 plan tests => scalar user_agents;
15
16 test_all_user_agents {
17 plan tests => 10;
18
19 my $ua = shift;
20 my $any_ua = HTTP::AnyUA->new(ua => $ua, response_is_future => 1);
21
22 my $path = '/get-document';
23 my $url = $server->url . $path;
24 my $future = $any_ua->head($url);
25
26 $future->on_ready(sub {
27 my $self = shift;
28 my $resp = $self->is_done ? $self->get : $self->failure;
29 my $env = $server->read_env;
30
31 note explain 'RESPONSE: ', $resp;
32 note explain 'ENV: ', $env;
33
34 SKIP: {
35 skip 'unexpected env', 2 if ref($env) ne 'HASH';
36 is($env->{REQUEST_METHOD}, 'HEAD', 'correct method sent');
37 is($env->{REQUEST_URI}, $path, 'correct url sent');
38 }
39
40 is_response_reason($resp, 'OK');
41 is_response_status($resp, 200);
42 is_response_success($resp, 1);
43 is_response_url($resp, $url);
44 is_response_header($resp, 'content-type', 'text/plain');
45 is_response_header($resp, 'content-length', 18);
46 response_protocol_ok($resp);
47
48 my $body = ref($resp) eq 'HASH' && $resp->{content};
49 ok(!$body, 'response body is empty');
50 });
51
52 return $future;
53 };
54
This page took 0.034501 seconds and 4 git commands to generate.