c++proxylibcurlpac

how to read PAC file using C++


I am using libcurl for HTTP requests.

My application should be able to understand the proxy settings if the user has any

So it can be Proxy by proxy server or Proxy by Auto proxy Configuration

I see support for PAC isnt available in libcurl

Since my application is in C++, are there any extension / parser engine available?

Thanks for reading the post


Solution

  • PAC (Proxy Auto Config) file is simply Javascript that has function FindProxyForURL returning proxy config string.

    Technically, this function can use anything that Javascript can do, so you must bundle some Javascript engine to interpret it.

    tiny-js (simple single-file javascript interpreter written in C++) is the library that should fit the bill for this task.

    UPDATE: pacparser library is pretty much ready-to-use engine designed specifically to parse pac files. Its downside that it bundles whole SpiderMonkey Javascript engine, which makes it rather heavy solution - it would add 1MB+ to your project binaries just to parse pac files.

    If you can hack pacparser to use tiny-js instead of SpiderMonkey, that would be really nice solution.