hakobe (owner)

Revisions

gist: 142163 Download_button fork
public
Public Clone URL: git://gist.github.com/142163.git
Embed All Files: show embed
get_or_post.pl #
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
use strict;
use warnings;
use HTTP::Engine;
use HTTP::Engine::Response;
use YAML::Syck qw(Dump);
 
sub p {
    print STDERR @_, "\n";
}
 
HTTP::Engine->new(
    interface => {
        module => 'ServerSimple',
        args => {
            host => 'localhost',
            port => 3000,
        },
        request_handler => sub {
            my $req = shift;
            my $res = HTTP::Engine::Response->new;
 
            my $redirect = $req->param('redirect');
 
            p '-' x 80;
            p $req->method;
            for my $key ($req->param) {
                p "$key = " . $req->param($key);
            }
            
            if ($redirect && $redirect =~ m/^\d\d\d$/) {
                $res->status($redirect);
                $res->headers->header(Location => 'http://localhost:3000/another/path');
            }
            else {
                $res->status(200);
                $res->body($req->method);
            }
            p $res->status;
            return $res;
        },
    },
)->run;