Skip to content

Instantly share code, notes, and snippets.

@nikushi
Created October 10, 2012 03:18
Show Gist options
  • Save nikushi/3862969 to your computer and use it in GitHub Desktop.
Save nikushi/3862969 to your computer and use it in GitHub Desktop.
tiny httpd written in perl
use strict;
use warnings;
use HTTP::daemon;
use HTTP::Status;
use HTTP::Response;
my $d = HTTP::Daemon->new(
LocalAddr => '127.0.0.1',
LocalPort => '10080',
)|| die;
print "access ", $d->url, "\n";
while ( my $c = $d->accept ) {
while( my $r = $c->get_request ) {
if ( $r->method eq 'GET' ) {
my $resp_hdr = HTTP::Headers->new('Content-Type' => 'text/plain');
my $resp = HTTP::Response->new('200', 'OK', $resp_hdr, "hogehoge\r\n");
$c->send_response($resp);
} else {
$c->send_error(RC_FORBIDDEN);
}
}
$c->close;
undef($c);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment