AnyEvent-HTTP-LWP-UserAgent

 view release on metacpan or  search on metacpan

t/response_content_cb.t  view on Meta::CPAN

{
    package HTTP::Server::Simple::Test;
    our @ISA = 'HTTP::Server::Simple::CGI';

    sub print_banner { }

    sub handle_request {
        my ($self, $cgi) = @_;

        if($cgi->url(-path_info=>1) =~ m,/error$,) {
            print "HTTP/1.0 404 Not found\r\n";
            print "Content-Type: text/plain\r\n";
            print "\r\n";
            print "404 Not found";
            return;
        }
        print "HTTP/1.0 200 OK\r\n";
        print "Content-Type: text/html\r\n";
        print "Set-Cookie: test=abc; path=/\r\n";
        print "\r\n";
        print <<__HTML__;
<html>
  <head>
    <title>Test Web Page</title>

t/response_content_cb.t  view on Meta::CPAN

            is $res->content, '', 'empty content when client died';
            like $res->header('X-Died'), qr/Died by client/, 'X-Died: when client died';
            like $res->header('Client-Aborted'), qr/die/, 'Client-Aborted: when client died';
        }
        {
            my $ua = $pkg->new(cookie_jar => {});
            my $content = '';
            my $res = $ua->get("http://localhost:$port/error", ':content_cb' => sub { $content .= $_[0] });
            ok !$res->is_success, '!is_success when error';
            is $content, '', 'callback when error';
            is $res->content, '404 Not found', 'content when error';
        }
    },
);

t/response_content_file.t  view on Meta::CPAN

{
    package HTTP::Server::Simple::Test;
    our @ISA = 'HTTP::Server::Simple::CGI';

    sub print_banner { }

    sub handle_request {
        my ($self, $cgi) = @_;

        if($cgi->url(-path_info=>1) =~ m,/error$,) {
            print "HTTP/1.0 404 Not found\r\n";
            print "Content-Type: text/plain\r\n";
            print "\r\n";
            print "404 Not found";
            return;
        }
        print "HTTP/1.0 200 OK\r\n";
        print "Content-Type: text/html\r\n";
        print "Set-Cookie: test=abc; path=/\r\n";
        print "\r\n";
        print <<__HTML__;
<html>
  <head>
    <title>Test Web Page</title>

t/response_content_file.t  view on Meta::CPAN

                open my $fh, '<', $temp;
                like <$fh>, qr{<p>blahblahblha</p>}, 'valid file';
                close $fh;
            }
        }
        {
            my $ua = $pkg->new(cookie_jar => {});
            my $temp = File::Temp->new;
            my $res = $ua->get("http://localhost:$port/error", ':content_file' => $temp->filename);
            ok !$res->is_success, '!is_success when error';
            is $res->content, '404 Not found', 'content when error';
            {
                local $/;
                open my $fh, '<', $temp;
                is <$fh>, '', 'file when error';
                close $fh;
            }
        }
    },
);



( run in 0.362 second using v1.01-cache-2.11-cpan-39bf76dae61 )