#!/usr/bin/perl # tiny test server: /a /b /c serve t1.html with different Content-Type headers use IO::Socket; my %ct = ("/a" => "text/html", "/b" => "text/html; charset=UTF-8", "/c" => "text/html;charset=UTF-8", "/d" => "text/html; charset=ISO-8859-1"); my $s = IO::Socket::INET->new(LocalPort => 8077, Listen => 5, Reuse => 1) or die "listen: $!"; open(F, "/tmp/mt/t1.html"); my $body = join("", ); close F; while (my $c = $s->accept) { my $req = <$c>; while (<$c>) { last if /^\r?\n$/ } my ($p) = $req =~ m{^GET (\S+)}; print STDERR "$p\n"; print $c "HTTP/1.0 200 OK\r\nContent-Type: ", ($ct{$p} || "text/plain"), "\r\nContent-Length: ", length($body), "\r\n\r\n", $body; close $c; }