File: 701-content-type-is-actionpack.t

package info (click to toggle)
libweb-machine-perl 0.17-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 940 kB
  • sloc: perl: 5,481; makefile: 2
file content (68 lines) | stat: -rw-r--r-- 1,426 bytes parent folder | download | duplicates (5)
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
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/perl

use strict;
use warnings;

use FindBin;
use HTTP::Request;
use Plack::Test;
use Plack::Util;
use Test::More;
use Web::Machine;

# Normally we'd use done_testing but the test is in the resource code so we
# need to make sure it gets called at all.
plan tests => 1;

=pod

This references https://github.com/houseabsolute/webmachine-perl/issues/27

We need to ensure that we always get the Content-Type header by calling
$request->header('Content-Type') rather than $request->content_type. The
latter doesn't actually look at the headers object, meaning we don't get the
inflated ActionPack header.

=cut

{
    package My::Resource::Test701;

    use strict;
    use warnings;

    use parent 'Web::Machine::Resource';

    use Test::More;

    sub allowed_methods { ['POST'] }

    sub content_types_provided {
        [
            {
                'text/plain' => sub { return 'foo' }
            }
        ];
    }

    sub process_post { \202 }

    sub known_content_type {
        isa_ok(
            $_[1],
            'HTTP::Headers::ActionPack::MediaType',
            'values passed to known_content_type'
        );
        return 1;
    }
}

test_psgi(
    Web::Machine->new( resource => 'My::Resource::Test701' )->to_app,
    sub {
        my $cb = shift;
        my $req = HTTP::Request->new( 'POST', '/' );
        $req->header( 'Content-Type' => 'text/plain' );
        $cb->($req);
    }
);