summaryrefslogtreecommitdiffstats
path: root/modules/httplib
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-04-26 02:48:12 +0800
committerGitHub <noreply@github.com>2021-04-25 21:48:12 +0300
commit3d5bb3e6a34bfb8073f6c61eb506cbdc927efbd4 (patch)
treed73b126596baaa256efa5d06c5ce97c9141c7dbc /modules/httplib
parent6ea6e2b4eb339f58f805783532f1b481fec67375 (diff)
downloadgitea-3d5bb3e6a34bfb8073f6c61eb506cbdc927efbd4.tar.gz
gitea-3d5bb3e6a34bfb8073f6c61eb506cbdc927efbd4.zip
fix webhook timeout bug (#15613)
* Also fix the potential problem in httplib
Diffstat (limited to 'modules/httplib')
-rw-r--r--modules/httplib/httplib.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/modules/httplib/httplib.go b/modules/httplib/httplib.go
index 62f284d2e1..294ad0b70b 100644
--- a/modules/httplib/httplib.go
+++ b/modules/httplib/httplib.go
@@ -325,7 +325,7 @@ func (r *Request) getResponse() (*http.Response, error) {
trans = &http.Transport{
TLSClientConfig: r.setting.TLSClientConfig,
Proxy: proxy,
- Dial: TimeoutDialer(r.setting.ConnectTimeout, r.setting.ReadWriteTimeout),
+ Dial: TimeoutDialer(r.setting.ConnectTimeout),
}
} else if t, ok := trans.(*http.Transport); ok {
if t.TLSClientConfig == nil {
@@ -335,7 +335,7 @@ func (r *Request) getResponse() (*http.Response, error) {
t.Proxy = r.setting.Proxy
}
if t.Dial == nil {
- t.Dial = TimeoutDialer(r.setting.ConnectTimeout, r.setting.ReadWriteTimeout)
+ t.Dial = TimeoutDialer(r.setting.ConnectTimeout)
}
}
@@ -352,6 +352,7 @@ func (r *Request) getResponse() (*http.Response, error) {
client := &http.Client{
Transport: trans,
Jar: jar,
+ Timeout: r.setting.ReadWriteTimeout,
}
if len(r.setting.UserAgent) > 0 && len(r.req.Header.Get("User-Agent")) == 0 {
@@ -457,12 +458,12 @@ func (r *Request) Response() (*http.Response, error) {
}
// TimeoutDialer returns functions of connection dialer with timeout settings for http.Transport Dial field.
-func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) func(net, addr string) (c net.Conn, err error) {
+func TimeoutDialer(cTimeout time.Duration) func(net, addr string) (c net.Conn, err error) {
return func(netw, addr string) (net.Conn, error) {
conn, err := net.DialTimeout(netw, addr, cTimeout)
if err != nil {
return nil, err
}
- return conn, conn.SetDeadline(time.Now().Add(rwTimeout))
+ return conn, nil
}
}