So, to clarify:
1/ I have a proxy (Fiddler) running locally on port 88882/ my /etc/hosts file has an entry as follows: 127.0.0.1 fiddler3/ My HTTP_PROXY and HTTPS_PROXY environment variables are set to http://fiddler:8888 and https://fiddler:8888 respectively
if I then issue a request via curl then that request is picked up by the proxy.
However if I make the same request from my go application, the request appears to bypass the proxy and is sent directly. I'm perplexed.
The "Name Resolution" section of https://golang.org/pkg/net/ says:
On Unix systems, the resolver has two options for resolving names. It can use a pure Go resolver that sends DNS requests directly to the servers listed in /etc/resolv.conf, or it can use a cgo-based resolver that calls C library routines such as getaddrinfo and getnameinfo.
By default the pure Go resolver is used, because a blocked DNS request consumes only a goroutine, while a blocked C call consumes an operating system thread.
That might have some bearing on your problem. To see if it's the case, as the page suggests:
export GODEBUG=netdns=cgo # force cgo resolver
So, to clarify:
1/ I have a proxy (Fiddler) running locally on port 88882/ my /etc/hosts file has an entry as follows: 127.0.0.1 fiddler3/ My HTTP_PROXY and HTTPS_PROXY environment variables are set to http://fiddler:8888 and https://fiddler:8888 respectively
if I then issue a request via curl then that request is picked up by the proxy.
However if I make the same request from my go application, the request appears to bypass the proxy and is sent directly. I'm perplexed.
The "Name Resolution" section in https://golang.org/pkg/net/ says:On Unix systems, the resolver has two options for resolving names. It can use a pure Go resolver that sends DNS requests directly to the servers listed in /etc/resolv.conf, or it can use a cgo-based resolver that calls C library routines such as getaddrinfo and getnameinfo.
By default the pure Go resolver is used, because a blocked DNS request consumes only a goroutine, while a blocked C call consumes an operating system thread.
That might have some bearing on your problem. To see if it's the case, as the page suggests:
export GODEBUG=netdns=cgo # force cgo resolver
Best Regards,
Adrian
Just a complete shot in the dark. Have you verified that the
environment variables you set are indeed getting picked up inside
of your application? Try checking the output of
os.GetEnv("HTTP_PROXY"), os.GetEnv("HTTPS_PROXY"), and
os.GetEnv("NO_PROXY"). Make sure that if NO_PROXY is set that it
isn't overriding your local proxy.
You could also try setting the lowercase versions of these env
vars:
https://github.com/golang/net/blob/master/http/httpproxy/proxy.go
func FromEnvironment() *Config {
return &Config{
HTTPProxy: getEnvAny("HTTP_PROXY", "http_proxy"),
HTTPSProxy: getEnvAny("HTTPS_PROXY", "https_proxy"),
NoProxy: getEnvAny("NO_PROXY", "no_proxy"),
CGI: os.Getenv("REQUEST_METHOD") != "",
}
}
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/ac6c1bae-2153-41b3-9037-110fc0eb12cfn%40googlegroups.com.