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

18 Replies, 1331 Views

For golang how to use forward http proxy, here’s a real-world example with auth:

```go
proxyURL := "http://user:pass@proxy:port"
transport := &http.Transport{
Proxy: http.ProxyURL(proxyURL),
IdleConnTimeout: 30 * time.Second,
}
client := &http.Client{Transport: transport}
```

Biggest gotcha? *Always* close response bodies (`defer resp.Body.Close()`), or you’ll leak connections.

Messages In This Thread



Users browsing this thread: 1 Guest(s)