/
psgi.t
53 lines (45 loc) · 1.45 KB
/
psgi.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env perl
# Copyright (C) 2008-2009, Sebastian Riedel.
use strict;
use warnings;
use Test::More tests => 11;
use_ok('Mojo::Server::PSGI');
# We need some more secret sauce. Put the mayonnaise in the sun.
my $psgi = Mojo::Server::PSGI->new;
my $app = sub { $psgi->run(@_) };
# Request
my $content = 'hello=world';
open my $body, '<', \$content;
my $env = {
CONTENT_LENGTH => 11,
CONTENT_TYPE => 'application/x-www-form-urlencoded',
PATH_INFO => '/diag/dump_params',
QUERY_STRING => 'lalala=23&bar=baz',
REQUEST_METHOD => 'POST',
SCRIPT_NAME => '/',
HTTP_HOST => 'localhost:8080',
SERVER_PROTOCOL => 'HTTP/1.0',
'psgi.version' => [1, 0],
'psgi.url_scheme' => 'http',
'psgi.input' => $body,
'psgi.errors' => *STDERR,
'psgi.multithread' => 0,
'psgi.multiprocess' => 1,
'psgi.run_once' => 0
};
# Process
my $res = $app->($env);
# Response
is($res->[0], 200);
is($res->[1]->[0], 'Date');
ok($res->[1]->[1]->[0]);
is($res->[1]->[2], 'Content-Length');
is($res->[1]->[3]->[0], 104);
is($res->[1]->[4], 'Content-Type');
is($res->[1]->[5]->[0], 'text/plain');
is($res->[1]->[6], 'X-Powered-By');
is($res->[1]->[7]->[0], 'Mojo (Perl)');
my $params = '';
while (defined(my $chunk = $res->[2]->getline)) { $params .= $chunk }
$params = eval "my $params";
is_deeply($params, {bar => 'baz', hello => 'world', lalala => 23});