CGI-Easy
view release on metacpan or search on metacpan
t/request.t view on Meta::CPAN
my $wait_all_params = {
name => ['powerman'],
'color[]' => ['red','green'],
};
$REQUEST = <<'EOF';
GET /?name=powerman&color[]=red&color%5B%5D=green HTTP/1.0
Host: example.com
EOF
setup_request({keep_all_values=>1}, 'http', $REQUEST);
is_deeply $r->{GET}, $wait_all_params, 'all params in {GET}';
########################
use utf8;
my $hi_str = 'ÐÑивеÑ';
my $hi_bin = $hi_str;
utf8::encode($hi_bin);
$REQUEST = <<"EOF";
GET /?greet=${\uri_escape($hi_bin)} HTTP/1.0
Host: example.com
EOF
setup_request({}, 'http', $REQUEST);
is_deeply $r->{GET}, {greet=>$hi_str}, 'Unicode param value';
setup_request({raw=>1}, 'http', $REQUEST);
is_deeply $r->{GET}, {greet=>$hi_bin}, 'raw param value';
$REQUEST = <<"EOF";
GET /?${\uri_escape($hi_bin)}=greet HTTP/1.0
Host: example.com
Cookie: greet=${\uri_escape($hi_bin)}; ${\uri_escape($hi_bin)}=greet
EOF
setup_request({}, 'http', $REQUEST);
is_deeply $r->{GET}, {$hi_str=>'greet'}, 'Unicode param name';
is $r->{cookie}{greet}, $hi_str, 'Unicode cookie value';
is $r->{cookie}{$hi_str}, 'greet', 'Unicode cookie name';
setup_request({raw=>1}, 'http', $REQUEST);
is_deeply $r->{GET}, {$hi_bin=>'greet'}, 'raw param name';
is $r->{cookie}{greet}, $hi_bin, 'raw cookie value';
is $r->{cookie}{$hi_bin}, 'greet', 'raw cookie name';
$REQUEST = <<"EOF";
POST / HTTP/1.0
Host: example.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 85
greet=${\uri_escape($hi_bin)}\&${\uri_escape($hi_bin)}=greet
EOF
setup_request({}, 'http', $REQUEST);
is $r->{POST}{greet}, $hi_str, 'POST Unicode value';
is $r->{POST}{$hi_str}, 'greet', 'POST Unicode name';
setup_request({raw=>1}, 'http', $REQUEST);
is $r->{POST}{greet}, $hi_bin, 'POST raw value';
is $r->{POST}{$hi_bin}, 'greet', 'POST raw name';
$REQUEST = <<"EOF";
POST /upload/ HTTP/1.0
Host: example.com
Content-Type: multipart/form-data; boundary=----------2A33hj1wqbMp0fkWlQoYU5
Content-Length: AUTO
------------2A33hj1wqbMp0fkWlQoYU5
Content-Disposition: form-data; name="greet"
$hi_bin
------------2A33hj1wqbMp0fkWlQoYU5
Content-Disposition: form-data; name="$hi_bin"
greet
------------2A33hj1wqbMp0fkWlQoYU5
Content-Disposition: form-data; name="avatar"; filename="C:\\images\\$hi_bin.png"
Content-Type: image/png
$hi_bin
------------2A33hj1wqbMp0fkWlQoYU5--
EOF
setup_request({}, 'http', $REQUEST);
is $r->{POST}{greet}, $hi_str, 'POST multipart Unicode value';
is $r->{POST}{$hi_str}, 'greet', 'POST multipart Unicode name';
is $r->{POST}{avatar}, $hi_bin, 'POST multipart raw file';
is $r->{filename}{avatar}, "C:\\images\\$hi_str.png", 'POST multipart Unicode filename';
########################
$REQUEST = <<'EOF';
POST /?a=5&b=6&name=someone&color[]=blue HTTP/1.0
Host: example.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 43
name=powerman&color[]=red&color%5B%5D=green
EOF
setup_request({post_with_get=>1}, 'http', $REQUEST);
is_deeply [sort $r->param()], [sort 'a','b','name','color[]'], 'param()';
is scalar $r->param('a'), 5, 'scalar param(a)';
is scalar $r->param('b'), 6, 'scalar param(b)';
is scalar $r->param('name'), 'powerman', 'scalar param(name)';
is scalar $r->param('color[]'), 'red', 'scalar param(color[])';
is_deeply [$r->param('a')], [5], 'array param(a)';
is_deeply [$r->param('b')], [6], 'array param(b)';
is_deeply [$r->param('name')], ['powerman','someone'], 'array param(name)';
is_deeply [$r->param('color[]')], ['red','green','blue'], 'array param(color[]) SCALAR';
setup_request({}, 'http', $REQUEST);
is_deeply [sort $r->param()], [sort 'name','color[]'], 'param()';
is scalar $r->param('name'), 'powerman', 'scalar param(name)';
is scalar $r->param('color[]'), 'red', 'scalar param(color[])';
is_deeply [$r->param('name')], ['powerman'], 'array param(name)';
is_deeply [$r->param('color[]')], ['red','green'], 'array param(color[]) SCALAR';
( run in 1.432 second using v1.01-cache-2.11-cpan-b16cb0d3907 )