增加反向代理的等待时间

huangapple go评论90阅读模式
英文:

Increase the waiting time for ReverseProxy

问题

我的客户正在使用ReverseProxy来调用另一个服务,该服务最多需要60秒来响应我的请求。但是我的客户只等待30-35秒。我需要增加等待时间到60秒。我该如何做到这一点?

英文:

My client is using ReverseProxy to call another service that service takes maximum of 60 seconds to respond to my request. But my client is waiting for only 30-35 seconds. I need to increase the waiting time 60 seconds. How can I do that?

答案1

得分: 4

你可能正在使用DefaultTransport(默认超时时间为30秒)

需要设置代理请求的Transport

尝试添加以下内容来设置超时时间:

reverseproxy.Transport=&http.Transport{
	Proxy: http.ProxyFromEnvironment,
	DialContext: (&net.Dialer{
		Timeout:   60 * time.Second,
		KeepAlive: 60 * time.Second,
		DualStack: true,
	}).DialContext,
	MaxIdleConns:          100,
	IdleConnTimeout:       90 * time.Second,
	TLSHandshakeTimeout:   10 * time.Second,
	ExpectContinueTimeout: 1 * time.Second,
}
英文:

You are probably using the DefaultTransport (default timeout is 30 seconds)

Transport for proxy request needs to be set.

Try adding something like this for setting timeout:

reverseproxy.Transport=&http.Transport{
	Proxy: http.ProxyFromEnvironment,
	DialContext: (&net.Dialer{
		Timeout:   60 * time.Second,
		KeepAlive: 60 * time.Second,
		DualStack: true,
	}).DialContext,
	MaxIdleConns:          100,
	IdleConnTimeout:       90 * time.Second,
	TLSHandshakeTimeout:   10 * time.Second,
	ExpectContinueTimeout: 1 * time.Second,
}

答案2

得分: 0

proxy.Transport = &http.Transport{
ResponseHeaderTimeout: 5 * time.Second,
}

就这样就可以了。

英文:
proxy.Transport = &http.Transport{
	ResponseHeaderTimeout: 5 * time.Second,
}

That's enough

huangapple
  • 本文由 发表于 2017年7月29日 07:04:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/45383546.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定