]> Dogcows Code - chaz/p5-HTTP-AnyUA/blob - t/15-custom-method.t
Version 0.900
[chaz/p5-HTTP-AnyUA] / t / 15-custom-method.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 => 13;
18
19 my $ua = shift;
20 my $any_ua = HTTP::AnyUA->new(ua => $ua, response_is_future => 1);
21
22 my $method = 'FOOBAR';
23 my $path = '/get-document';
24 my $url = $server->url . $path;
25 my $future = $any_ua->request($method => $url, {headers => {'x-test-custom' => 'whatever'}});
26
27 $future->on_ready(sub {
28 my $self = shift;
29 my $resp = $self->is_done ? $self->get : $self->failure;
30 my $env = $server->read_env;
31
32 note explain 'RESPONSE: ', $resp;
33 note explain 'ENV: ', $env;
34
35 SKIP: {
36 skip 'unexpected env', 4 if ref($env) ne 'HASH';
37 is($env->{REQUEST_METHOD}, $method, 'correct method sent');
38 is($env->{REQUEST_URI}, $path, 'correct url sent');
39 is($env->{content}, '', 'no body sent');
40 is($env->{HTTP_X_TEST_CUSTOM}, 'whatever', 'custom header sent');
41 }
42
43 is_response_content($resp, 'this is a document');
44 is_response_reason($resp, 'OK');
45 is_response_status($resp, 200);
46 is_response_success($resp, 1);
47 is_response_url($resp, $url);
48 is_response_header($resp, 'content-type', 'text/plain');
49 is_response_header($resp, 'content-length', 18);
50 is_response_header($resp, 'x-foo', 'bar');
51 response_protocol_ok($resp);
52 });
53
54 return $future;
55 };
56
This page took 0.031137 seconds and 4 git commands to generate.