Mini httpd

Aus SiWiki
Wechseln zu: Navigation, Suche
#!/usr/bin/perl
use strict;
use IO::Socket;
 
my $listensock=IO::Socket::INET6->new(Proto=>"tcp", LocalPort=>8000, Listen=>2, Reuse=>1) or die "failed to listen";
 
while( (my $con = $listensock->accept()) ) {
	my $request=<$con>;
  	$request =~ m!GET ([^ ]+) HTTP/1\..\r?\n!;
	open(INFILE, "<", "./$1");
	print $con "HTTP/1.0 200 OK\nContent-type: text/html\n\n", <INFILE>;
	close $con;
}