2 # Thanks to merlyn for nudging me and giving me this snippet!
9 my $d = HTTP::Daemon->new or die;
12 my ($filename,$logfile) = @ARGV[0,1];
14 open DATA, "< $filename"
15 or die "Couldn't read page '$filename' : $!\n";
17 open LOG, ">", $logfile
18 or die "Couldn't create logfile '$logfile' : $!\n";
19 my $body = join "", <DATA>;
23 $message =~ s!\n!\n#SERVER:!g;
24 warn "#SERVER: $message"
25 if $ENV{TEST_HTTP_VERBOSE};
30 while (my $c = $d->accept) {
31 debug "New connection";
32 while (my $r = $c->get_request) {
33 print LOG "Request:\n" . $r->as_string . "\n";
34 debug "Request:\n" . $r->as_string;
35 my $location = ($r->uri->path || "/");
36 my ($link1,$link2) = ('','');
37 if ($location =~ m!^/link/([^/]+)/(.*)$!) {
38 ($link1,$link2) = ($1,$2);
41 if ($location =~ m!^/redirect/(.*)$!) {
42 $res = HTTP::Response->new(302);
43 $res->header('location', $d->url . $1);
45 my $q = CGI->new($r->uri->query);
47 # Make sticky form fields
48 my ($query,$session,%cat);
49 $query = defined $q->param('query') ? $q->param('query') : "(empty)";
50 $session = defined $q->param('session') ? $q->param('session') : 1;
51 %cat = map { $_ => 1 } (defined $q->param('cat') ? $q->param('cat') : qw( cat_foo cat_bar ));
52 my @categories = map { $cat{$_} ? "checked" : "" } qw( cat_foo cat_bar cat_baz );
53 $res = HTTP::Response->new(200, "OK", undef, sprintf($body,$location,$session,$query,@categories));
54 $res->content_type('text/html; charset=utf8');
55 debug "Request " . ($r->uri->path || "/");
56 if ( $location eq '/quit_server') {
58 $c->force_last_request;
63 debug "Response:\n" . $res->as_string;
64 $c->send_response($res);
73 END { debug "Server stopped" };
78 <title>WWW::Mechanize::Shell test page</title>
83 <a href="/test">Link /test</a>
84 <a href="/foo">Link /foo</a>
85 <a href="/slash_end">Link /</a>
86 <a href="/slash_front">/Link </a>
87 <a href="/slash_both">/Link in slashes/</a>
88 <a href="/foo1.save_log_server_test.tmp">Link foo1.save_log_server_test.tmp</a>
89 <a href="/foo2.save_log_server_test.tmp">Link foo2.save_log_server_test.tmp</a>
90 <a href="/foo3.save_log_server_test.tmp">Link foo3.save_log_server_test.tmp</a>
91 <a href="/o-umlaut">Löschen -- testing for o-umlaut.</a>
92 <a href="/o-umlaut-encoded">Stösberg -- testing for encoded o-umlaut.</a>
95 <tr><th>Col1</th><th>Col2</th><th>Col3</th></tr>
96 <tr><td>A1</td><td>A2</td><td>A3</td></tr>
97 <tr><td>B1</td><td>B2</td><td>B3</td></tr>
98 <tr><td>C1</td><td>C2</td><td>C3</td></tr>
100 <form name="f" action="/formsubmit">
101 <input type="hidden" name="session" value="%s"/>
102 <input type="text" name="query" value="%s"/>
103 <input type="submit" name="submit" value="Go"/>
104 <input type="checkbox" name="cat" value="cat_foo" %s />
105 <input type="checkbox" name="cat" value="cat_bar" %s />
106 <input type="checkbox" name="cat" value="cat_baz" %s />
107 <input type="file" name="upload" value="README" />