This package provides a pure Go pac parser based on otto
package main
import (
"fmt"
"github.com/darren/gpac"
)
var scripts = `
function FindProxyForURL(url, host) {
if (isPlainHostName(host)) return DIRECT;
else return "PROXY 127.0.0.1:8080; PROXY 127.0.0.1:8081; DIRECT";
}
`
func main() {
pac, _ := gpac.New(scripts)
r, _ := pac.FindProxyForURL("http://www.example.com/")
fmt.Println(r) // returns PROXY 127.0.0.1:8080; PROXY 127.0.0.1:8081; DIRECT
// Get issues request via a list of proxies and returns at the first request that succeeds
resp, _ := pac.Get("http://www.example.com/")
fmt.Println(resp.Status)
}
There's a simple tool that wraps curl
and wget
for pac file support.
go get github.com/darren/gpac/gpacw
gpacw wpad.dat curl -v http://example.com
gpacw http://wpad/wpad.dat wget -O /dev/null http://example.com
note url should be the last argument of the command or it will fail.