File: request.pl

package info (click to toggle)
libplack-request-withencoding-perl 0.14-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 152 kB
  • sloc: perl: 118; makefile: 7
file content (30 lines) | stat: -rw-r--r-- 784 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env perl

use strict;
use warnings;
use utf8;
use FindBin;
use lib "$FindBin::Bin/../lib";

use Plack::Request::WithEncoding;

my $app_or_middleware = sub {
    my $env = shift; # PSGI env

    # Example of $env
    #
    # $env = {
    #     QUERY_STRING   => 'query=%82%d9%82%b0', # <= encoded by 'cp932'
    #     REQUEST_METHOD => 'GET',
    #     HTTP_HOST      => 'example.com',
    #     PATH_INFO      => '/foo/bar',
    # };

    my $req = Plack::Request::WithEncoding->new($env);
    $req->env->{'plack.request.withencoding.encoding'} = 'cp932'; # <= specify the encoding method.

    my $query = $req->param('query'); # <= get parameters of 'query' that is decoded by 'cp932'.

    my $res = $req->new_response(200); # new Plack::Response
    $res->finalize;
};