# Thanks to merlyn for nudging me and giving me this snippet!
use strict;
use HTTP::Daemon;

$|++;

my $d = HTTP::Daemon->new or die;
print $d->url, "\n";

my $body = join "", <DATA>;

sub debug($) {
  warn "#SERVER: $_[0]\n" 
    if $ENV{TEST_HTTP_VERBOSE};
};

SERVERLOOP: {
  my $quitserver;
  while (my $c = $d->accept) {
    debug "New connection";
    while (my $r = $c->get_request) {
      my $location = ($r->uri->path || "/");
      my $res = HTTP::Response->new(200, "OK", undef, sprintf($body,$location));
      $res->content_type('text/html');
      debug "Request " . ($r->uri->path || "/");
      if ( $location eq '/quit_server') {
        debug "Quitting";
        $c->force_last_request;
        $quitserver = 1;
      };
      $c->send_response($res);
      last if $quitserver;
    }
    $c->close;
    undef($c);
    last SERVERLOOP
      if $quitserver;
  }
};
END { debug "Server stopped" };

__DATA__
<html>
<head>WWW::Mechanize::Shell test page</head>
<body>
<h1>Location: %s</h1>
<p>
  <a href="/test">Link /test</a>
  <a href="/foo">Link /foo</a>
  <a href="/foo1.save_log_server_test.tmp">Link foo1.save_log_server_test.tmp</a>
  <a href="/foo2.save_log_server_test.tmp">Link foo2.save_log_server_test.tmp</a>
  <a href="/foo3.save_log_server_test.tmp">Link foo3.save_log_server_test.tmp</a>
  <table>
    <tr><th>Col1</th><th>Col2</th><th>Col3</th></tr>
    <tr><td>A1</td><td>A2</td><td>A3</td></tr>
    <tr><td>B1</td><td>B2</td><td>B3</td></tr>
    <tr><td>C1</td><td>C2</td><td>C3</td></tr>    
  </table>
  <form action="/formsubmit">
    <input type="hidden" name="session" value="1"/>
    <input type="text" name="query" value="empty"/>
    <input type="submit" name="submit" value="Go"/>
  </form>
</p>
</body>
</html>