Skip to content

Instantly share code, notes, and snippets.

@hakobe
Created July 7, 2009 15:41
Show Gist options
  • Select an option

  • Save hakobe/142163 to your computer and use it in GitHub Desktop.

Select an option

Save hakobe/142163 to your computer and use it in GitHub Desktop.
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment