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 $res = $ua->get( url("/someplace", $base) );
97 #print $res->as_string;
98 print "not " unless $res->is_success;
101 $res = $ua->get( url("/private/place", $base) );
102 #print $res->as_string;
103 print "not " unless $res->code == 403
104 and $res->message =~ /robots.txt/;
108 $res = $ua->get( url("/foo", $base) );
109 #print $res->as_string;
110 print "not " unless $res->code == 404; # not found
113 # Let the robotua generate "Service unavailable/Retry After response";
117 $res = $ua->get( url("/foo", $base) );
118 #print $res->as_string;
119 print "not " unless $res->code == 503 # Unavailable
120 and $res->header("Retry-After");
123 #----------------------------------------------------------------
124 print "Terminating server...\n";
128 $c->send_error(503, "Bye, bye");
129 exit; # terminate HTTP server
134 $res = $ua->get( url("/quit", $base) );
136 print "not " unless $res->code == 503 and $res->content =~ /Bye, bye/;
139 #---------------------------------------------------------------
142 # host_wait() should be around 60s now
143 print "not " unless abs($ua->host_wait($base->host_port) - 60) < 5;
146 # Number of visits to this place should be
147 print "not " unless $ua->no_visits($base->host_port) == 4;
150 # RobotUA used to have problem with mailto URLs.
151 $ENV{SENDMAIL} = "dummy";
152 $res = $ua->get("mailto:gisle\@aas.no");
153 #print $res->as_string;
155 print "not " unless $res->code == 400 && $res->message eq "Library does not allow method GET for 'mailto:' URLs";