Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: lwp proxy problem

by bronto (Priest)
on Apr 27, 2004 at 15:52 UTC ( [id://348547]=note: print w/replies, xml ) Need Help??


in reply to lwp proxy problem

I downloaded the file using wget, getting:

$ wget -O - http://www.tau.ac.il/tau.pac --17:49:19-- http://www.tau.ac.il/tau.pac => `-' Resolving www.tau.ac.il... 132.66.16.6 Connecting to www.tau.ac.il[132.66.16.6]:80... connected. HTTP request sent, awaiting response... 200 OK Length: 1,187 [application/x-ns-proxy-autoconfig] 0% [ ] 0 --.--K/s +function FindProxyForURL(url, host) { if ((isInNet(myIpAddress(), "132.66.90.0", "255.255.254.0")) & +& !dnsDomainIs(host, "www.tau.ac.il")) { return "PROXY proxyslb.tau.ac.il:8080; " + "PROXY proxy.tau.ac.il:8080; " + "PROXY netcache.tau.ac.il:8080; " + "PROXY netcache2.tau.ac.il:8080; " + "PROXY proxym.tau.ac.il:8080; " + "PROXY 132.66.16.12:8080; " + "PROXY 132.66.16.34:8080; " + "PROXY 132.66.16.23:8080"; } else if (isInNet(host, "132.66.58.20", "255.255.255.255")) { return "PROXY proxym.tau.ac.il:8080"; } else if (isPlainHostName(host) || isInNet(host, "127.0.0.1", "255.255.255.255") || isInNet(host, "132.66.0.0", "255.254.0.0")) { return "DIRECT"; } else { return "PROXY proxyslb.tau.ac.il:8080; " + "PROXY proxy.tau.ac.il:8080; " + "PROXY netcache.tau.ac.il:8080; " + "PROXY netcache2.tau.ac.il:8080; " + "PROXY proxym.tau.ac.il:8080; " + "PROXY 132.66.16.12:8080; " + "PROXY 132.66.16.34:8080; " + "PROXY 132.66.16.23:8080"; } }

It is easy to read, so I think that once you know your IP address you can pick a proxy from the list by hand

Or you can write a script yourself to parse the pac file, at the moment I have no time to sketch one, sorry :-(

Update: see HTTP::ProxyAutoConfig

Update: try this and tell me if it works. It seems I can't use that proxy, so I couldn't make any test myself, apart from checking that it parses and runs correctly.

use HTTP::ProxyAutoConfig ; use LWP::Simple qw(&getstore $ua); + my $pac = new HTTP::ProxyAutoConfig("http://www.tau.ac.il/tau.pac"); + my $url='http://www.yahoo.com'; $ua->proxy(http => $pac->FindProxy($url)); + my $file='test.html'; print "success" if (getstore($url, $file));

Update: actually, that won't work, since you need to parse the return value from FindProxy and pass it to $ua->proxy only if it matches /PROXY: host:port/ (after cleaning up the PROXY: parts, of course). Unfortunately, I am having no luck in making this module work (the FindProxyForURL function doesn't get defined). I'll update the above script as soon as I make sense of the module...

Update: Ok, I checked with ptkdb and saw that:

  • the module tries to parse the function contained in the pac file (javascript) to convert it to Perl
  • the parser in the subroutine is very buggy, and probabily expects a certain format for the PAC file, that is: is not general enough to parse any pac
  • the converted function is finally eval'ed, but no check is done on the $@ variable. Therefore, the user doesn't know if the pac failed to parse until he tries to use the FindProxy* functions and sees them fail because FindProxyForURL doesn't exist

Possible solutions:

  • write a bug report for the module and wait for the author to patch his module
  • write a better parsing routine, or ask for one (I can't write one, I am a JavaScript illiterate :-)
  • rewrite the parser routine using one of the JavaScript modules from CPAN. This one, for example, uses the SpiderMonkey engine from Mozilla, and I expect that it will know how to parse the PAC

Sorry, I can't help further :-(

Ciao!
--bronto


The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
--John M. Dlugosz

Replies are listed 'Best First'.
Re: Re: lwp proxy problem
by dannoura (Pilgrim) on Apr 27, 2004 at 16:15 UTC

    Thanks for your help. It's not working, though. I get two errors:

    Useless use of a constant in void context at C:/perl/site/lib/HTTP/Pro +xyAutoConfig.pm line 367. Undefined subroutine &HTTP::ProxyAutoConfig::FindProxyForURL called at + C:/perl/site/lib/HTTP/ProxyAutoConfig.pm line 131.

    -----------------------------------

    Any comments about coding style are welcome.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://348547]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-25 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found