CGI-Easy
view release on metacpan or search on metacpan
t/request.t view on Meta::CPAN
setup_request({}, 'http', $REQUEST);
is $r->{ENV}{REQUEST_METHOD}, 'PUT', 'method PUT';
is_deeply $r->{GET}, {}, 'empty {GET}';
is_deeply $r->{POST}, $wait_params, 'params in {POST}';
$REQUEST = <<'EOF';
POST /?a=5&b=6 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 $r->{ENV}{REQUEST_METHOD}, 'POST', 'method POST';
is_deeply $r->{GET}, {a=>5,b=>6}, 'params in {GET}';
is_deeply $r->{POST}, $wait_params, 'params in {POST}';
########################
$REQUEST = <<'EOF';
GET /?name=powerman&name=someone&color[]=red&color%5B%5D=green HTTP/1.0
Host: example.com
EOF
setup_request({}, 'http', $REQUEST);
is_deeply $r->{GET}, $wait_params, 'params in {GET}';
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
( run in 1.159 second using v1.01-cache-2.11-cpan-39bf76dae61 )