Leser: 2
9 Einträge, 1 Seite |
QuoteNoticing Redirection
Remember that ->request (as in ->head) can cause several real request/response cycles. Check ->previous!
To report redirection:
...
if(! $resp->is_success) {
print $url, "\n => ", $resp->status_line, "\n"
} elsif($resp->previous and $resp->previous->is_redirect) {
print "## Moved $url\n## => ", $resp->request->url, "\n";
} else {
print "## OK: $url\n";
}
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
[LUNA] C:\>nc www.nabooisland.com 80
HEAD /temp/dcsm.htm HTTP/1.1
If-Modified-Since: Tue, 10 Aug 2004 22:43:52 GMT
Host: www.nabooisland.com
Connection: close
HTTP/1.1 301 Moved Permanently
Date: Thu, 12 Aug 2004 22:45:46 GMT
Server: Apache/1.3.31
Location: http://www.nabooisland.com
Connection: close
Content-Type: text/html; charset=iso-8859-1
...
[LUNA] C:\>nc www.nabooisland.com 80
HEAD / HTTP/1.1
Host: www.nabooisland.com
If-Modified-Since: Tue, 10 Aug 2004 22:43:52 GMT
Connection: close
HTTP/1.1 304 Not Modified
Date: Thu, 12 Aug 2004 22:41:07 GMT
Server: Apache/1.3.31
Connection: close
ETag: "42405e-1a77-40a530e6"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
sub check {
my ($url) = shift;
$url =~ m{http://([^\:|/]*)}s;
my $host = $1;
my $req = HTTP::Request->new(HEAD => $url);
$req->header('Host' => $host);
$req->header('If-Modified-Since' => time2str($mtime));
my $resp;
$resp = $ua->request($req) or warn "Response fuer $url fehlgeschlagen: ",$resp->status_line,"\n";
print $resp->is_success;
if(! $resp->is_success and $resp->code == RC_NOT_MODIFIED) {
print "$url wurde seit ",time2str($mtime)," nicht geaendert.\n";
} elsif (! $resp->is_success) {
print $url, " => ", $resp->status_line, "\n";
} elsif($resp->previous and $resp->previous->is_redirect) {
check($resp->request->url);
} else {
print "$url wurde geaendert!\n";
}
}
1
2
3
4
5
6
7
8
9
10
11
12
sub check_url { # given an absolute URL
my $url = $_[0];
my $resp = $browser->head($url);
if(!$resp->is_success) {
print $url, "\n => ", $resp->status_line, "\n";
} elsif($resp->previous and $resp->previous->is_redirect) {
check_url($resp->request->url);
# print "## Moved $url\n## => ", $resp->request->url, "\n";
} else {
print "## OK: $url\n";
}
}
9 Einträge, 1 Seite |