HTTP-Tiny-FileProtocol

 view release on metacpan or  search on metacpan

lib/HTTP/Tiny/FileProtocol.pm  view on Meta::CPAN

        $bytes = length $content;
    }

    my $response = {
        url     => $url,
        success => $success,
        status  => $status,
        ( !$success ? (reason  => $reason) : () ),
        content => $content // '',
        headers => {
            'content-type'   => $content_type,
            'content-length' => $bytes // 0,
        },
    };

    return $response;
}

1;

__END__

t/02_get_file.t  view on Meta::CPAN

{
    use bytes;
    $content_length = length $content;
}

my $check = {
    success => 1,
    status  => 200,
    content => $content // '',
    headers => {
        'content-type'   => 'text/plain',
        'content-length' => $content_length // 0,
    },
};

is $response->{status}, 200;
is_deeply $response, $check;
is_string $content, $response->{content};

done_testing();

t/03_get_xlsx.t  view on Meta::CPAN

{
    use bytes;
    $content_length = length $content;
}

my $check = {
    success => 1,
    status  => 200,
    content => $content // '',
    headers => {
        'content-type'   => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        'content-length' => $content_length // 0,
    },
};

is $response->{status}, 200;
is_deeply $response, $check;
is_string $content, $response->{content};

done_testing();

t/04_not_found.t  view on Meta::CPAN

my $response = $http->get('file://' . $file);

delete $response->{url};

my $check = {
    success => undef,
    status  => 404,
    reason  => 'File Not Found',
    content => '',
    headers => {
        'content-type'   => 'text/plain',
        'content-length' => 0,
    },
};

is $response->{status}, 404;
is_deeply $response, $check;

done_testing();

t/06_build_response.t  view on Meta::CPAN

my $url = 'file:///test.txt';

{
    is_deeply $sub->( $url, 1, 200, '', '', 'text/plain' ),
        {
            url     => $url,
            success => 1,
            status  => 200,
            content => '',
            headers => { 
                'content-type'   => 'text/plain',
                'content-length' => 0,
            }, 
        }
}

{
    is_deeply $sub->( $url, 1, 200, '', undef, 'text/plain' ),
        {
            url     => $url,
            success => 1,
            status  => 200,
            content => '',
            headers => { 
                'content-type'   => 'text/plain',
                'content-length' => 0,
            }, 
        }
}

{
    is_deeply $sub->( $url, 0, 200, 'Not found', 'test', 'text/plain' ),
        {
            url     => $url,
            success => 0,
            status  => 200,
            reason  => 'Not found',
            content => 'test',
            headers => { 
                'content-type'   => 'text/plain',
                'content-length' => 4,
            }, 
        }
}

done_testing();

t/08_cando.t  view on Meta::CPAN

my $http = HTTP::Tiny->new;
isa_ok $http, 'HTTP::Tiny';
can_ok $http, 'get';

{
    my $response = $http->get('file://' . __FILE__ );
    delete $response->{url};
    is_deeply $response, {
        'status' => 403,
        'headers' => {
            'content-type' => 'text/plain',
            'content-length' => 0
        },
        'content' => '',
        'success' => undef,
        'reason' => 'Permission Denied',
    };
}

done_testing();



( run in 1.316 second using v1.01-cache-2.11-cpan-524268b4103 )