英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论