cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: 'automatic configuration script' as proxy

From: Ralph Mitchell <rmitchell_at_eds.com>
Date: Wed, 03 Mar 2004 10:33:06 -0600

Edward S. Peschko wrote:

>there's a button in opera, mozilla and ie - 'use automatic configuration script'.
>
>As far as I can see, this button lets you define a function FindProxyForURL
>which takes two arguments - url and host.
>
>It then returns either 'DIRECT' or 'PROXY ....' depending on which host and url
>you are at and trying to reach, to a given host based on the contents of that
>funciton, which may or may not take authentication depending on what the proxy
>sends back.
>
>

This doesn't need to be integrated into curl - at least, not the command
line tool. You can do this in the script you wrap around the tool. Use
curl to grab the PAC file, shove it through js along with the url you're
checking out, pick up the response and decide how to continue.

>So, IMO, the scope of the problem is limited - in order to support this you don't
>need to support all the uses and execution of javascript, just the execution
>of one function which returns a string.
>
>

Where I work, the PAC file uses various methods to break up the url
and/or hostname into component parts and substrings. It even uses some
functions that are not programmed into the interpreter, but rather are
javascript functions themselves. That's why I had to dig up the
builtins I referred to yesterday. I think you have to assume the PAC
writer will use anything listed in the PAC configuration manual:

    function FindProxyForURL(url, host)
    {
        if ((isPlainHostName(host)) ||
            (host.substring(0, 9) == "127.0.0.1") ||
            (host.substring(0, 13) == "10.133.96.252") ||
            (host.toUpperCase() == "HOST.DOMAIN.COM")||
            (dnsDomainIs(host, ".internal.domain.com")) ||
            (shExpMatch(host, "box*.domain.com")) ||
          etc...

Mind you, this is a multinational company with one of the largest
private networks in the world.

>Of course, people could as a matter of course do incredibly fancy things with
>their javascript, in forwarding to a proxy, but they don't really do this with
>the automatic proxy configuration script. In the admittedly small sample size
>that I have had access to (4 sites which used this) they've all had a bunch
>of if-then statements based on url and host to determine how to route it.
>
>[snip]
>
>
>The fact that curl doesn't handle automatic proxy configuration - which is standard
>in all browsers - *does*. That's why it should support it - its directly
>in the problem domain that curl sets up for itself.
>
>

So handle it in the script external to curl. Or in whatever language
you're using. I mostly use Bourne shell, but just last night I had a go
at building the js interpreter into Daniel's getinmemory.c example
program. It still needs some work, but I've got a working
libcurl/javascript program that I can hand the PAC location and a url
and get back "DIRECT" or "PROXY http://xxx.domain.com".

Of course, the result need not be printed out - it could be used
internally in the C program to go on and fetch the target url. This
opens another can of worms, though - we have several different proxies
here, which fortunately all require the same userid/password. Imagine
the fun we'd have with PACs and multiple different userid/passwords...

If things are quiet at work tonight, I'll see about banging out an
example program and some instructions on building it.

Ralph
Received on 2004-03-03