Skip to content

Commit

Permalink
No need for another block
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 22, 2020
1 parent 0deed31 commit 0a32fd8
Showing 1 changed file with 75 additions and 81 deletions.
156 changes: 75 additions & 81 deletions t/mojo/cgi.t
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,17 @@ subtest 'Reverse proxy' => sub {

subtest 'Simple' => sub {
my $msg = '';
{
local *STDOUT;
open STDOUT, '>', \$msg;
local %ENV = (
PATH_INFO => '/',
REQUEST_METHOD => 'GET',
SCRIPT_NAME => '/',
HTTP_HOST => 'localhost:8080',
SERVER_PROTOCOL => 'HTTP/1.0'
);
is(Mojolicious::Command::cgi->new(app => app)->run, 200, 'right status');
}
local *STDOUT;
open STDOUT, '>', \$msg;
local %ENV = (
PATH_INFO => '/',
REQUEST_METHOD => 'GET',
SCRIPT_NAME => '/',
HTTP_HOST => 'localhost:8080',
SERVER_PROTOCOL => 'HTTP/1.0'
);
is(Mojolicious::Command::cgi->new(app => app)->run, 200, 'right status');

my $res = Mojo::Message::Response->new->parse("HTTP/1.1 200 OK\x0d\x0a$msg");
is $res->code, 200, 'right status';
is $res->headers->status, '200 OK', 'right "Status" value';
Expand All @@ -70,18 +69,17 @@ subtest 'Simple' => sub {

subtest 'HEAD request' => sub {
my $msg = '';
{
local *STDOUT;
open STDOUT, '>', \$msg;
local %ENV = (
PATH_INFO => '/',
REQUEST_METHOD => 'HEAD',
SCRIPT_NAME => '/',
HTTP_HOST => 'localhost:8080',
SERVER_PROTOCOL => 'HTTP/1.0'
);
is(Mojolicious::Command::cgi->new(app => app)->run, 200, 'right status');
}
local *STDOUT;
open STDOUT, '>', \$msg;
local %ENV = (
PATH_INFO => '/',
REQUEST_METHOD => 'HEAD',
SCRIPT_NAME => '/',
HTTP_HOST => 'localhost:8080',
SERVER_PROTOCOL => 'HTTP/1.0'
);
is(Mojolicious::Command::cgi->new(app => app)->run, 200, 'right status');

my $res = Mojo::Message::Response->new->parse("HTTP/1.1 200 OK\x0d\x0a$msg");
is $res->code, 200, 'right status';
is $res->headers->status, '200 OK', 'right "Status" value';
Expand All @@ -93,19 +91,18 @@ subtest 'HEAD request' => sub {

subtest 'Non-parsed headers' => sub {
my $msg = '';
{
local *STDOUT;
open STDOUT, '>', \$msg;
local %ENV = (
PATH_INFO => '/',
REQUEST_METHOD => 'GET',
SCRIPT_NAME => '/',
HTTP_HOST => 'localhost:8080',
SERVER_PROTOCOL => 'HTTP/1.0'
);
is(Mojolicious::Command::cgi->new(app => app)->run('--nph'),
200, 'right status');
}
local *STDOUT;
open STDOUT, '>', \$msg;
local %ENV = (
PATH_INFO => '/',
REQUEST_METHOD => 'GET',
SCRIPT_NAME => '/',
HTTP_HOST => 'localhost:8080',
SERVER_PROTOCOL => 'HTTP/1.0'
);
is(Mojolicious::Command::cgi->new(app => app)->run('--nph'),
200, 'right status');

my $res = Mojo::Message::Response->new->parse($msg);
is $res->code, 200, 'right status';
is $res->headers->status, undef, 'no "Status" value';
Expand All @@ -118,22 +115,21 @@ subtest 'Non-parsed headers' => sub {
subtest 'Chunked' => sub {
my $content = 'test1=1&test2=2&test3=3&test4=4&test5=5&test6=6&test7=7';
my $msg = '';
{
local *STDIN;
open STDIN, '<', \$content;
local *STDOUT;
open STDOUT, '>', \$msg;
local %ENV = (
PATH_INFO => '/chunked',
CONTENT_LENGTH => length($content),
CONTENT_TYPE => 'application/x-www-form-urlencoded',
REQUEST_METHOD => 'POST',
SCRIPT_NAME => '/',
HTTP_HOST => 'localhost:8080',
SERVER_PROTOCOL => 'HTTP/1.0'
);
is(Mojolicious::Command::cgi->new(app => app)->run, 200, 'right status');
}
local *STDIN;
open STDIN, '<', \$content;
local *STDOUT;
open STDOUT, '>', \$msg;
local %ENV = (
PATH_INFO => '/chunked',
CONTENT_LENGTH => length($content),
CONTENT_TYPE => 'application/x-www-form-urlencoded',
REQUEST_METHOD => 'POST',
SCRIPT_NAME => '/',
HTTP_HOST => 'localhost:8080',
SERVER_PROTOCOL => 'HTTP/1.0'
);
is(Mojolicious::Command::cgi->new(app => app)->run, 200, 'right status');

like $msg, qr/chunked/, 'is chunked';
my $res = Mojo::Message::Response->new->parse("HTTP/1.1 200 OK\x0d\x0a$msg");
is $res->code, 200, 'right status';
Expand All @@ -143,19 +139,18 @@ subtest 'Chunked' => sub {

subtest 'Parameters' => sub {
my $msg = '';
{
local *STDOUT;
open STDOUT, '>', \$msg;
local %ENV = (
PATH_INFO => '/params',
QUERY_STRING => 'lalala=23&bar=baz',
REQUEST_METHOD => 'GET',
SCRIPT_NAME => '/',
HTTP_HOST => 'localhost:8080',
SERVER_PROTOCOL => 'HTTP/1.0'
);
is(Mojolicious::Command::cgi->new(app => app)->run, 200, 'right status');
}
local *STDOUT;
open STDOUT, '>', \$msg;
local %ENV = (
PATH_INFO => '/params',
QUERY_STRING => 'lalala=23&bar=baz',
REQUEST_METHOD => 'GET',
SCRIPT_NAME => '/',
HTTP_HOST => 'localhost:8080',
SERVER_PROTOCOL => 'HTTP/1.0'
);
is(Mojolicious::Command::cgi->new(app => app)->run, 200, 'right status');

my $res = Mojo::Message::Response->new->parse("HTTP/1.1 200 OK\x0d\x0a$msg");
is $res->code, 200, 'right status';
is $res->headers->status, '200 OK', 'right "Status" value';
Expand All @@ -168,21 +163,20 @@ subtest 'Parameters' => sub {

subtest 'Reverse proxy' => sub {
my $msg = '';
{
local *STDOUT;
open STDOUT, '>', \$msg;
local %ENV = (
PATH_INFO => '/proxy',
REQUEST_METHOD => 'GET',
SCRIPT_NAME => '/',
HTTP_HOST => 'localhost:8080',
SERVER_PROTOCOL => 'HTTP/1.0',
'HTTP_X_Forwarded_For' => '192.0.2.2, 192.0.2.1',
'HTTP_X_Forwarded_Proto' => 'https'
);
local $ENV{MOJO_REVERSE_PROXY} = 1;
is(Mojolicious::Command::cgi->new(app => app)->run, 200, 'right status');
}
local *STDOUT;
open STDOUT, '>', \$msg;
local %ENV = (
PATH_INFO => '/proxy',
REQUEST_METHOD => 'GET',
SCRIPT_NAME => '/',
HTTP_HOST => 'localhost:8080',
SERVER_PROTOCOL => 'HTTP/1.0',
'HTTP_X_Forwarded_For' => '192.0.2.2, 192.0.2.1',
'HTTP_X_Forwarded_Proto' => 'https'
);
local $ENV{MOJO_REVERSE_PROXY} = 1;
is(Mojolicious::Command::cgi->new(app => app)->run, 200, 'right status');

my $res = Mojo::Message::Response->new->parse("HTTP/1.1 200 OK\x0d\x0a$msg");
is $res->code, 200, 'right status';
is $res->headers->status, '200 OK', 'right "Status" value';
Expand Down

0 comments on commit 0a32fd8

Please sign in to comment.