Created
November 8, 2018 17:37
-
-
Save viniciusdaniel/3f48cfa969608101f20fbc6f9150613e to your computer and use it in GitHub Desktop.
Small webserver just responding HTTP 200
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use IO::Socket; | |
my $server = IO::Socket::INET->new( | |
LocalPort => 80, | |
Type => SOCK_STREAM, | |
Reuse => 1, | |
Listen => 20 | |
) or die "Can't start socket $@\n"; | |
my $client; | |
my $message; | |
while ($client = $server->accept()) { | |
my $received; | |
while(<$client>) { | |
$message = $_; | |
last if $message =~ /^\s+$/; | |
$received .= $message; | |
} | |
print $client "HTTP/1.1 200 OK\r\n"; | |
print $client "Content-type: text/html\r\n\r\n"; | |
print $client '<!DOCTYPE html><html><head><title>OK</title></head>'; | |
print $client '<body><pre>' . $received . '</pre></body></html>'; | |
print $client "\r\n"; | |
close($client); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment