6 unless (-f "CAN_TALK_TO_OURSELF") {
7 print "1..0 # Skipped: Can't talk to ourself (misconfigured system)\n";
12 require IO::Socket; # make sure this work before we try to make a HTTP::Daemon
14 # First we make ourself a daemon in another process
20 my $d = new HTTP::Daemon Timeout => 10;
22 print "Please to meet you at: <URL:", $d->url, ">\n";
23 open(STDOUT, $^O eq 'MSWin32' ? ">nul" : $^O eq 'VMS' ? ">NL:" : ">/dev/null");
25 while ($c = $d->accept) {
28 my $p = ($r->url->path_segments)[1];
30 my $func = lc("httpd_" . $r->method . "_$p");
31 #print STDERR "Calling $func...\n";
39 $c = undef; # close connection
41 print STDERR "HTTP Server terminated\n";
46 my $perl = $Config{'perlpath'};
47 $perl = $^X if $^O eq 'VMS' or -x $^X and $^X =~ m,^([a-z]:)?/,i;
48 open(DAEMON , "$perl robot/ua.t daemon |") or die "Can't exec daemon: $!";
55 $greating =~ /(<[^>]+>)/;
58 my $base = URI->new($1);
61 $u = $u->abs($_[1]) if @_ > 1;
65 print "Will access HTTP server at $base\n";
68 require HTTP::Request;
69 $ua = new LWP::RobotUA 'lwp-spider/0.1', 'gisle@aas.no';
70 $ua->delay(0.05); # rather quick robot
72 #----------------------------------------------------------------
73 sub httpd_get_robotstxt
76 $c->send_basic_header;
77 $c->print("Content-Type: text/plain");
80 $c->print("User-Agent: *
86 sub httpd_get_someplace
89 $c->send_basic_header;
90 $c->print("Content-Type: text/plain");
93 $c->print("Okidok\n");
96 $req = new HTTP::Request GET => url("/someplace", $base);
97 $res = $ua->request($req);
98 #print $res->as_string;
99 print "not " unless $res->is_success;
102 $req = new HTTP::Request GET => url("/private/place", $base);
103 $res = $ua->request($req);
104 #print $res->as_string;
105 print "not " unless $res->code == 403
106 and $res->message =~ /robots.txt/;
109 $req = new HTTP::Request GET => url("/foo", $base);
110 $res = $ua->request($req);
111 #print $res->as_string;
112 print "not " unless $res->code == 404; # not found
115 # Let the robotua generate "Service unavailable/Retry After response";
118 $req = new HTTP::Request GET => url("/foo", $base);
119 $res = $ua->request($req);
120 #print $res->as_string;
121 print "not " unless $res->code == 503 # Unavailable
122 and $res->header("Retry-After");
125 #----------------------------------------------------------------
126 print "Terminating server...\n";
130 $c->send_error(503, "Bye, bye");
131 exit; # terminate HTTP server
135 $req = new HTTP::Request GET => url("/quit", $base);
136 $res = $ua->request($req);
138 print "not " unless $res->code == 503 and $res->content =~ /Bye, bye/;
141 #---------------------------------------------------------------
144 # host_wait() should be around 60s now
145 print "not " unless abs($ua->host_wait($base->host_port) - 60) < 5;
148 # Number of visits to this place should be
149 print "not " unless $ua->no_visits($base->host_port) == 4;