Skip to content

Instantly share code, notes, and snippets.

@miyagawa
Created June 10, 2011 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miyagawa/1019207 to your computer and use it in GitHub Desktop.
Save miyagawa/1019207 to your computer and use it in GitHub Desktop.
# It is valid for an HTTP header to span multiple lines, as long as the continuation lines start with
# at least one space. This should be taken into account when parsing headers.
use Test::More 'no_plan';
use CGI::Application::Emulate::PSGI;
use CGI::Application;
use HTTP::Message::PSGI qw(req_to_psgi);
use HTTP::Request;
my $env = req_to_psgi( HTTP::Request->new(GET => "/") );
{
my $psgi_app = CGI::Application::Emulate::PSGI->handler(sub {
my $webapp = CGI::Application->new;
$webapp->header_add( -zoo => "single-line header" );
$webapp->run();
});
my ($out) = $psgi_app->($env);
my ($status,$headers) = @$out;
my %headers = @$headers;
is($status,200, "got 200 status");
like($headers{Zoo}, qr{single}, "Zoo matches 'single'");
like($headers{"Content-Type"}, qr{text/html}, "header header value matches text/html");
}
{
my $psgi_app = CGI::Application::Emulate::PSGI->handler(sub {
my $webapp = CGI::Application->new;
$webapp->header_add( -foo => "multi-line: header\n fools: you?" );
$webapp->run();
});
my ($out) = $psgi_app->($env);
my ($status,$headers) = @$out;
my %headers = @$headers;
is($status,200, "got 200 status");
like($headers{Zoo}, qr{fools: Your}, "Zoo header value matches 'fools: you'");
like($headers{"Content-Type"}, qr{text/html}, "header header value matches text/html");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment