forked from petdance/test-www-mechanize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hanger
executable file
·84 lines (60 loc) · 1.74 KB
/
hanger
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!perl
# This program only exists to figure out why perl 5.12.0 RC1 hangs when
# trying to test PUT in Test::WWW::Mechanize.
use strict;
use warnings;
use WWW::Mechanize;
my $server = HangServer->new;
my $pid = $server->background;
print "Running as pid $pid\n";
my $server_root = $server->root;
my $mech = WWW::Mechanize->new;
GOOD_GET: {
my $goodlinks = "$server_root/goodlinks.html";
$mech->get( $goodlinks );
$mech->success or die "Unable to get $goodlinks";
print "=== GET content ===\n";
print $mech->content, "\n";
print "=== GET content ===\n";
}
print "\n\nHit enter to do a PUT. You can also go elsewhere and connect to $server_root";
my $f = <>;
GOOD_GET: {
my $scraps = "$server_root/scraps.html";
$mech->put( $scraps );
print "=== PUT content ===\n";
print $mech->content, "\n";
print "=== PUT content ===\n";
print 'Success in the PUT? ', ($mech->success ? 'YES' : 'NO'), '\n';
}
print "\n\nHit enter to down the server";
$f = <>;
print "Killing pid $pid\n";
kill( 9, $pid ) unless $^S;
print "Server stopped\n";
exit;
package HangServer;
use warnings;
use strict;
use base 'HTTP::Server::Simple::CGI';
sub new {
my $class = shift;
# XXX This should really be a random port.
return $class->SUPER::new(13432, @_);
}
sub handle_request {
my $self = shift;
my $cgi = shift;
use Data::Dumper; local $Data::Dumper::Sortkeys=1;
my $response = Dumper($cgi);
$response .= '$cgi->path_info is [' . $cgi->path_info . ']';
print "HTTP/1.0 200 OK\r\n";
print "Content-Type: text/html\r\nContent-Length: ", length($response), "\r\n\r\n", $response;
return;
}
sub root {
my $self = shift;
my $port = $self->port;
return "http://localhost:$port";
}
1;