Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions modules/httplib/httplib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
}
8 changes: 2 additions & 6 deletions services/webhook/deliver.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,10 @@ func InitDeliverHooks() {
TLSClientConfig: &tls.Config{InsecureSkipVerify: setting.Webhook.SkipTLSVerify},
Proxy: webhookProxy(),
Dial: func(netw, addr string) (net.Conn, error) {
conn, err := net.DialTimeout(netw, addr, timeout)
if err != nil {
return nil, err
}

return conn, conn.SetDeadline(time.Now().Add(timeout))
return net.DialTimeout(netw, addr, timeout) // dial timeout
},
},
Timeout: timeout, // request timeout
}

go graceful.GetManager().RunWithShutdownContext(DeliverHooks)
Expand Down