Catalyst-Engine-HTTP-Prefork
view release on metacpan or search on metacpan
inc/Module/Install/Fetch.pm view on Meta::CPAN
require Cwd;
my $dir = Cwd::getcwd();
chdir $args{local_dir} or return if exists $args{local_dir};
if (eval { require LWP::Simple; 1 }) {
LWP::Simple::mirror($args{url}, $file);
}
elsif (eval { require Net::FTP; 1 }) { eval {
# use Net::FTP to get past firewall
my $ftp = Net::FTP->new($host, Passive => 1, Timeout => 600);
$ftp->login("anonymous", 'anonymous@example.com');
$ftp->cwd($path);
$ftp->binary;
$ftp->get($file) or (warn("$!\n"), return);
$ftp->quit;
} }
elsif (my $ftp = $self->can_run('ftp')) { eval {
# no Net::FTP, fallback to ftp.exe
require FileHandle;
my $fh = FileHandle->new;
t/live_http11_request_absolute.t view on Meta::CPAN
my $server = URI->new( $ENV{CATALYST_SERVER} || 'http://localhost' );
my $base = $server->host . ':' . $server->port;
# Test absolute request
{
my $sock = IO::Socket::INET->new(
PeerAddr => $server->host,
PeerPort => $server->port,
Proto => 'tcp',
ReuseAddr => 1,
Timeout => 2,
) or die "Cannot connect to $server";
# Send request
syswrite $sock, construct_request( "http://$base/dump/request", 'foo.bar.com:3000' );
# Read/parse response
sysread $sock, my $buf, 64 * 1024;
my $response = HTTP::Response->parse($buf);
is( $response->code, 200, 'Response ok' );
t/live_http11_request_absolute.t view on Meta::CPAN
like( $creq->base, qr/$base/, 'base uses host from absolute request' );
}
# Test normal request without Host header
{
my $sock = IO::Socket::INET->new(
PeerAddr => $server->host,
PeerPort => $server->port,
Proto => 'tcp',
ReuseAddr => 1,
Timeout => 2,
) or die "Cannot connect to $server";
# Send request
syswrite $sock, construct_request( "/dump/request" );
# Read/parse response
sysread $sock, my $buf, 64 * 1024;
my $response = HTTP::Response->parse($buf);
is( $response->code, 400, 'Invalid response ok' );
t/live_http11_request_pipelined.t view on Meta::CPAN
"http://$base/dump/request?req=4",
);
# Make first request normally, we then reuse the keep-alive connection
# to pipeline the next 3 requests
my $sock = IO::Socket::INET->new(
PeerAddr => $server->host,
PeerPort => $server->port,
Proto => 'tcp',
ReuseAddr => 1,
Timeout => 2,
) or die "Cannot connect to $server";
# Send request
syswrite $sock, construct_request( shift @reqs );
# Read/parse response
sysread $sock, my $buf, 64 * 1024;
my $response = HTTP::Response->parse($buf);
is( $response->code, 200, 'Response ok' );
t/live_http11_response_100continue.t view on Meta::CPAN
my $server = URI->new( $ENV{CATALYST_SERVER} || 'http://localhost' );
my $base = $server->host . ':' . $server->port;
# Test 100-continue with HTTP/1.1 request
{
my $sock = IO::Socket::INET->new(
PeerAddr => $server->host,
PeerPort => $server->port,
Proto => 'tcp',
ReuseAddr => 1,
Timeout => 2,
) or die "Cannot connect to $server";
# Send request
syswrite $sock, construct_request( "http://$base/dump/request", '1.1', '100-continue' );
# Read/parse response
sysread $sock, my $buf, 64 * 1024;
like( $buf, qr{^HTTP/1.1 100 Continue}, '100 Continue ok' );
t/live_http11_response_100continue.t view on Meta::CPAN
is_deeply( $creq->{parameters}, $expected, 'Parameters ok' );
}
# Test invalid Expect header
{
my $sock = IO::Socket::INET->new(
PeerAddr => $server->host,
PeerPort => $server->port,
Proto => 'tcp',
ReuseAddr => 1,
Timeout => 2,
) or die "Cannot connect to $server";
# Send request
syswrite $sock, construct_request( "http://$base/dump/request", '1.1', '200-bleh' );
# Read/parse response
sysread $sock, my $buf, 64 * 1024;
like( $buf, qr{^HTTP/1.1 417}, 'Invalid expect returned 417' );
}
# Test Expect header with HTTP/1.0
{
my $sock = IO::Socket::INET->new(
PeerAddr => $server->host,
PeerPort => $server->port,
Proto => 'tcp',
ReuseAddr => 1,
Timeout => 2,
) or die "Cannot connect to $server";
# Send request
syswrite $sock, construct_request( "http://$base/dump/request", '1.0', '100-continue' );
# Continue sending a POST body
syswrite $sock, 'one=foo&two=bar';
# Read/parse response
sysread $sock, my $buf, 64 * 1024;
t/live_http11_response_chunked.t view on Meta::CPAN
{
my $server = URI->new( $ENV{CATALYST_SERVER} || 'http://localhost' );
my $base = $server->host . ':' . $server->port;
my $sock = IO::Socket::INET->new(
PeerAddr => $server->host,
PeerPort => $server->port,
Proto => 'tcp',
ReuseAddr => 1,
Timeout => 2,
) or die "Cannot connect to $server";
# Send request
syswrite $sock, construct_request( "http://$base/streaming" );
# Read all responses into one big buffer
my $buf;
my $sel = IO::Select->new($sock);
while ( $sel->can_read(1) ) {
my $n = sysread $sock, my $buf2, 64 * 1024;
t/live_http11_response_keepalive.t view on Meta::CPAN
my $server = URI->new( $ENV{CATALYST_SERVER} || 'http://localhost' );
my $base = $server->host . ':' . $server->port;
# Test normal HTTP/1.1 request, should return Connection: keep-alive
{
my $sock = IO::Socket::INET->new(
PeerAddr => $server->host,
PeerPort => $server->port,
Proto => 'tcp',
ReuseAddr => 1,
Timeout => 2,
) or die "Cannot connect to $server";
# Send request
syswrite $sock, construct_request( "http://$base/dump/request", '1.1', 'keep-alive' );
# Read/parse response
sysread $sock, my $buf, 64 * 1024;
my $response = HTTP::Response->parse($buf);
is( $response->header('Connection'), 'keep-alive', 'HTTP/1.1, keep-alive ok' );
}
# Test HTTP/1.1 with Connection: close, should return Connection: close
{
my $sock = IO::Socket::INET->new(
PeerAddr => $server->host,
PeerPort => $server->port,
Proto => 'tcp',
ReuseAddr => 1,
Timeout => 2,
) or die "Cannot connect to $server";
# Send request
syswrite $sock, construct_request( "http://$base/dump/request", '1.1', 'close' );
# Read/parse response
sysread $sock, my $buf, 64 * 1024;
my $response = HTTP::Response->parse($buf);
is( $response->header('Connection'), 'close', 'HTTP/1.1, close ok' );
}
# Test HTTP/1.0 with Connection: Keep-Alive header, should return Connection: keep-alive
{
my $sock = IO::Socket::INET->new(
PeerAddr => $server->host,
PeerPort => $server->port,
Proto => 'tcp',
ReuseAddr => 1,
Timeout => 2,
) or die "Cannot connect to $server";
# Send request
syswrite $sock, construct_request( "http://$base/dump/request", '1.0', 'keep-alive' );
# Read/parse response
sysread $sock, my $buf, 64 * 1024;
my $response = HTTP::Response->parse($buf);
is( $response->header('Connection'), 'keep-alive', 'HTTP/1.0, keep-alive ok' );
}
# Test HTTP/1.0 with no Connection header, should return Connection: close
{
my $sock = IO::Socket::INET->new(
PeerAddr => $server->host,
PeerPort => $server->port,
Proto => 'tcp',
ReuseAddr => 1,
Timeout => 2,
) or die "Cannot connect to $server";
# Send request
syswrite $sock, construct_request( "http://$base/dump/request", '1.0', '' );
# Read/parse response
sysread $sock, my $buf, 64 * 1024;
my $response = HTTP::Response->parse($buf);
is( $response->header('Connection'), 'close', 'HTTP/1.0, no Connection header ok' );
( run in 0.238 second using v1.01-cache-2.11-cpan-4d50c553e7e )