Furl

 view release on metacpan or  search on metacpan

t/400_components/01_headers.t  view on Meta::CPAN

    is( $h->header('X-Bar'), 2 );
    is_deeply( [$h->header('X-Bar')], [2] );
};

subtest 'shorthand' => sub {
    my $h = Furl::Headers->new(
        [
            'expires'           => '1111',
            'last-modified'     => '2222',
            'if-modified-since' => '3333',
            'content-type'      => 'text/html',
            'content-length'    => '4444',
        ]
    );
    is $h->expires,           '1111';
    is $h->last_modified,     '2222';
    is $h->if_modified_since, '3333';
    is $h->content_type,      'text/html';
    is $h->content_length,    4444;
};

t/400_components/02_response.t  view on Meta::CPAN

use Test::More;
use Test::Requires qw(Plack::Request HTTP::Body), 'HTTP::Response';
use Furl::Response;

my $res = Furl::Response->new(
    1, 200, 'OK',
    +{
        'x-foo'            => ['yay'],
        'x-bar'            => ['hoge'],
        'content-length'   => [9],
        'content-type'     => ['text/html'],
        'content-encoding' => ['chunked'],
    },
    'hit man'
);
is $res->protocol, 'HTTP/1.1';
is $res->code, 200;
is $res->message, 'OK';
isa_ok $res->headers, 'Furl::Headers';
is $res->content, 'hit man';
is($res->headers->header('X-Foo'), 'yay');

t/400_components/02_response.t  view on Meta::CPAN

        $dat, {
            message => 'OK',
            code => 200,
            content => 'hit man',
            protocol => 'HTTP/1.1',
        }
    );
    is_deeply(
        [sort @{$headers}],
        [sort qw(
            content-type text/html
            x-foo yay
            x-bar hoge
            content-length 9
            content-encoding chunked
        )]
    );
};

subtest 'to_psgi' => sub {
    my $dat = $res->to_psgi;
    is(0+@$dat, 3);
    is($dat->[0], 200);
    is_deeply(
        [sort @{$dat->[1]}],
        [sort qw(
            content-type text/html
            x-foo yay
            x-bar hoge
            content-length 9
            content-encoding chunked
        )]
    );
    is_deeply($dat->[2], ['hit man']);
};

subtest decoded_content => sub {
    my $res = Furl::Response->new(
        1, 200, 'OK',
        +{
            'content-type' => ['text/plain; charset=UTF-8'],
        },
        "\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212",
    );
    is $res->decoded_content, "\x{3042}\x{3044}\x{3046}\x{3048}\x{304a}";
};

subtest 'as_string' => sub {
    my $res = Furl::Response->new(
        1, 200, 'OK',
        +{
            'x-foo'            => ['yay'],
            'x-bar'            => ['hoge'],
            'content-length'   => [9],
            'content-type'     => ['text/html'],
            'content-encoding' => ['chunked'],
        },
        'hit man'
    );
    my $expected = join("\015\012",
        '200 OK',
        'content-encoding: chunked',
        'content-length: 9',
        'content-type: text/html',
        'x-bar: hoge',
        'x-foo: yay',
        '',
        'hit man',
    );
    is($res->as_string, $expected);
    is(length($res->as_string), length($expected));
};

done_testing;

t/400_components/03_request.t  view on Meta::CPAN

use Furl::Request;

subtest 'normally' => sub {
    my $req = Furl::Request->new(
        'POST',
        'http://example.com/foo?q=bar',
        +{
            'x-foo'            => ['yay'],
            'x-bar'            => ['hoge'],
            'content-length'   => [7],
            'content-type'     => ['text/plain'],
        },
        'hit man'
    );
    $req->protocol('HTTP/1.0');

    is $req->method, 'POST';
    is $req->uri, 'http://example.com/foo?q=bar';
    isa_ok $req->headers, 'Furl::Headers';
    is($req->header('X-Foo'), 'yay');
    is $req->content, 'hit man';

t/400_components/03_request.t  view on Meta::CPAN

};

subtest 'as_hashref' => sub {
    my $req = Furl::Request->new(
        'POST',
        'http://example.com/foo?q=bar',
        +{
            'x-foo'            => ['yay'],
            'x-bar'            => ['hoge'],
            'content-length'   => [7],
            'content-type'     => ['text/plain'],
        },
        'hit man'
    );
    $req->protocol('HTTP/1.1');

    my $dat = $req->as_hashref;

    my $headers = delete $dat->{headers};

    is_deeply(

t/400_components/03_request.t  view on Meta::CPAN

            method => 'POST',
            uri => 'http://example.com/foo?q=bar',
            content => 'hit man',
            protocol => 'HTTP/1.1',
        }
    );

    is_deeply(
        [sort @{$headers}],
        [sort qw(
            content-type text/plain
            content-length 7
            x-foo yay
            x-bar hoge
        )]
    );
};

subtest 'as_string' => sub {
    subtest 'simple' => sub {
        my $req = Furl::Request->new(
            'POST',
            'http://example.com/foo?q=bar',
            +{
                'x-foo'            => ['yay'],
                'x-bar'            => ['hoge'],
                'content-length'   => [7],
                'content-type'     => ['text/plain'],
            },
            'hit man'
        );
        $req->protocol('HTTP/1.1');

        my $expected = join("\015\012",
            'POST http://example.com/foo?q=bar HTTP/1.1',
            'content-length: 7',
            'content-type: text/plain',
            'x-bar: hoge',
            'x-foo: yay',
            '',
            'hit man',
        );
        is($req->as_string, $expected);
    };
    subtest 'Furl#post' => sub {
        my $req = Furl::Request->new(
            'POST',
            'http://example.com/foo?q=bar',
            +{
                'x-foo'            => ['yay'],
                'x-bar'            => ['hoge'],
                'content-length'   => [7],
                'content-type'     => ['text/plain'],
            },
            [X => 'Y'],
        );
        # no protocol

        my $expected = join("\015\012",
            'POST http://example.com/foo?q=bar',
            'content-length: 7',
            'content-type: text/plain',
            'x-bar: hoge',
            'x-foo: yay',
            '',
            'X=Y',
        );
        is($req->as_string, $expected);
    };
};

done_testing;



( run in 2.183 seconds using v1.01-cache-2.11-cpan-524268b4103 )