Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@ Usage:
PAC file name, url or javascript to use (required)
-l string
Interface and port to listen on (default "127.0.0.1:8080")
-s string
Scheme to use for the URL passed to FindProxyForURL
-v send verbose output to STDERR
```

```bash
# shell 1
pacproxy -c 'function FindProxyForURL(url, host){ console.log("hello pac world!"); return "PROXY random.example.com:8080"; }'
pacproxy -l 127.0.0.1:8080 -s http -c 'function FindProxyForURL(url, host){ console.log("hello pac world!"); return "PROXY random.example.com:8080"; }'
# shell 2
pacproxy -l 127.0.0.1:8443 -s https -c 'function FindProxyForURL(url, host){ console.log("hello pac world!"); return "PROXY random.example.com:8080"; }'
# shell 3
export http_proxy="127.0.0.1:8080"
export https_proxy="127.0.0.1:8080"
export https_proxy="127.0.0.1:8443"
curl -I "http://www.example.com"
curl -I "https://www.example.com"
```

## License
Expand Down
2 changes: 2 additions & 0 deletions pacproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ const Repo = "https://github.com/williambailey/pacproxy"
var (
fPac string
fListen string
fScheme string
fVerbose bool
)

func init() {
flag.StringVar(&fPac, "c", "", "PAC file name, url or javascript to use (required)")
flag.StringVar(&fListen, "l", "127.0.0.1:8080", "Interface and port to listen on")
flag.StringVar(&fScheme, "s", "", "Scheme to use for the URL passed to FindProxyForURL")
flag.BoolVar(&fVerbose, "v", false, "send verbose output to STDERR")
}

Expand Down
16 changes: 14 additions & 2 deletions proxyhttphandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,24 @@ func (h *proxyHTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

func (h *proxyHTTPHandler) lookupProxy(r *http.Request) (*url.URL, error) {
proxies, err := h.proxyFinder.FindProxyForURL(r.URL)
sourceURL := &url.URL{
Scheme: fScheme,
Opaque: r.URL.Opaque,
User: r.URL.User,
Host: r.URL.Host,
Path: r.URL.Path,
RawPath: r.URL.RawPath,
ForceQuery: r.URL.ForceQuery,
RawQuery: r.URL.RawQuery,
Fragment: r.URL.Fragment,
RawFragment: r.URL.RawFragment,
}
proxies, err := h.proxyFinder.FindProxyForURL(sourceURL)
if err != nil {
return nil, err
}
proxy := h.proxySelector.SelectProxy(proxies)
log.Printf("Proxy Lookup %q, got %q. Selected %q", r.URL, proxies, proxy)
log.Printf("Proxy Lookup %q, got %q. Selected %q", sourceURL, proxies, proxy)
if proxy == pac.DirectProxy {
return nil, nil
}
Expand Down