rendered paste bodysub web_size{
my $url = shift || die "Need URL to check";
REDIR:
{
$url =~ /^(http:\/\/)(.*?)(\/.*)$/;
my $protocol = $1;
my $domain = $2;
my $path = $3;
$domain = $domain.":80" unless ($domain =~ /80/);
my $handle = IO::Socket::INET->new($domain) || die "can't connect to $domain: $!";
$handle->autoflush(1);
print $handle <<EOF;
HEAD $path HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; X11; Linux i686; en) Opera 9.26
Host: $domain
Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1
Accept-Language: en,no
Accept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1
Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0
Connection: No Keep-Alive\n\n\n
EOF
my %data = ();
my $http;
while (<$handle>){
chomp;
$_ = lc;
#print $_."\n";
$http = $_ unless ($http);
my ($option,$result) = split(/: /);
$data{$option} = $result;
}
if ($http =~ /301|302/){
#print "Redir: ".$data{'location'}."\n";
$url = $data{'location'};
redo REDIR;
}else{
return $data{'content-length'}."\n";
}
}
}