Hello,
I am writing a redirector script for SQUID, and when I use URI
to parse the URL, URI is not functioning the same in "redirector" mode as it is
under command line mode...
i.e. The only difference is where the URL is coming from..and
URI doesn't appear to fully function, here is the code:
#!/usr/bin/perl -w
use URI; #Parse URL sub parse_url{ $URL=$ARGV[0]; my $u=URI->new($URL); my $scheme=$u->scheme; my $opaque=$u->opaque; my $authority=$u->authority; my $path=$u->path; my $fragment=$u->fragment; my $host=$u->host; my $query=$u->query; my @response=($scheme,$opaque,$authority,$path,$fragment,$host,$query); if($debug){print ERR "$host\n";} if($debug){print ERR "@response\n";} return(@response); } sub do_lookup { # Do SOME STUFF TO Find a mask for the URL. return($mask) } #MAIN URI Doesn't WORK Right Errors out with:Cannot find
Method{host} in _generic.
# Nothing is parsed
correctly...
$|=1; while(<>) { @X = split; $url = $X[0]; @url_array=parse_url($url); %url_array=( "scheme"=>shift(@url_array), "opaque"=>shift(@url_array), "authority"=>shift(@url_array), "path"=>shift(@url_array), "fragment"=>shift(@url_array), "host"=>shift(@url_array), "query"=>shift(@url_array)); if($debug){print "The contents of %url_array";} #YES PSEUDO CODE.... $mask=do_lookup($url_array{host}); if ($mask > 0) { print "http://auth1.s4f.com/blocked.asp\n"; }else{ print "$url\n"; } } #MAIN URI Works same program but instead of taking input from
STDIN, takes input from
#command line..same input..a URL. even prints the same $url = $ARGV[0];
@url_array=parse_url($url); %url_array=( "scheme"=>shift(@url_array), "opaque"=>shift(@url_array), "authority"=>shift(@url_array), "path"=>shift(@url_array), "fragment"=>shift(@url_array), "host"=>shift(@url_array), "query"=>shift(@url_array)); if($debug){print "The contents of %url_array";} #YES PSEUDO CODE.... $mask=do_lookup($url_array{host}); if ($mask > 0) { print "http://auth1.s4f.com/blocked.asp\n"; }else{ print "$url\n"; } In method 1, The Contents of %url_array are
empty...
In method 2, URI has parsed everything
correctly..i.e.
Scheme: http
opaque:http://www.playboy.com/somepath/somedoc.html?var=some&var2=else
authority:www.playboy.com
host:www.playboy.com
query:var=some&var2=else
fragment:
(I don't know if fragment works as I am not sure I understand
what it is since I have never had a url produce one..)
At any rate all those strings are empty in the first method
passed the exact same string..
Any CLues?
|
- Re: [Perl-unix-users] Problems with URI; Michael Wray
- Re: [Perl-unix-users] Problems with URI; $Bill Luebkert
- RE: [Perl-unix-users] Problems with URI; Steve Aaron