Golang how to use forward http proxy – Best way to configure it? or How to set up a forward HTTP prox

18 Replies, 1543 Views

Hey! For golang how to use forward http proxy, you can totally set the `HTTP_PROXY` env var, and the default `http.Client` will pick it up. But if you need more control, here's a quick snippet:

```go
proxyURL, _ := url.Parse("http://proxy-ip:port")
client := &http.Client{
Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)},
}
```

Works like a charm. If your proxy needs auth, check out `http.ProxyFromEnvironment` or set headers manually.

Btw, had timeout issues? Try tweaking `Transport` settings like `ResponseHeaderTimeout`.

Messages In This Thread



Users browsing this thread: 1 Guest(s)