@@ -374,6 +374,7 @@ func (c *Client) Post(dst []byte, url string, postArgs *Args) (statusCode int, b
374374//
375375// ErrTimeout is returned if the response wasn't returned during
376376// the given timeout.
377+ // Immediately returns ErrTimeout if timeout value is negative.
377378//
378379// ErrNoFreeConns is returned if all Client.MaxConnsPerHost connections
379380// to the requested host are busy.
@@ -387,6 +388,9 @@ func (c *Client) Post(dst []byte, url string, postArgs *Args) (statusCode int, b
387388// try setting a ReadTimeout.
388389func (c * Client ) DoTimeout (req * Request , resp * Response , timeout time.Duration ) error {
389390 req .timeout = timeout
391+ if req .timeout < 0 {
392+ return ErrTimeout
393+ }
390394 return c .Do (req , resp )
391395}
392396
@@ -407,6 +411,7 @@ func (c *Client) DoTimeout(req *Request, resp *Response, timeout time.Duration)
407411//
408412// ErrTimeout is returned if the response wasn't returned until
409413// the given deadline.
414+ // Immediately returns ErrTimeout if the deadline has already been reached.
410415//
411416// ErrNoFreeConns is returned if all Client.MaxConnsPerHost connections
412417// to the requested host are busy.
@@ -415,6 +420,9 @@ func (c *Client) DoTimeout(req *Request, resp *Response, timeout time.Duration)
415420// and AcquireResponse in performance-critical code.
416421func (c * Client ) DoDeadline (req * Request , resp * Response , deadline time.Time ) error {
417422 req .timeout = time .Until (deadline )
423+ if req .timeout < 0 {
424+ return ErrTimeout
425+ }
418426 return c .Do (req , resp )
419427}
420428
@@ -1139,6 +1147,7 @@ func ReleaseResponse(resp *Response) {
11391147//
11401148// ErrTimeout is returned if the response wasn't returned during
11411149// the given timeout.
1150+ // Immediately returns ErrTimeout if timeout value is negative.
11421151//
11431152// ErrNoFreeConns is returned if all HostClient.MaxConns connections
11441153// to the host are busy.
@@ -1152,6 +1161,9 @@ func ReleaseResponse(resp *Response) {
11521161// try setting a ReadTimeout.
11531162func (c * HostClient ) DoTimeout (req * Request , resp * Response , timeout time.Duration ) error {
11541163 req .timeout = timeout
1164+ if req .timeout < 0 {
1165+ return ErrTimeout
1166+ }
11551167 return c .Do (req , resp )
11561168}
11571169
@@ -1167,6 +1179,7 @@ func (c *HostClient) DoTimeout(req *Request, resp *Response, timeout time.Durati
11671179//
11681180// ErrTimeout is returned if the response wasn't returned until
11691181// the given deadline.
1182+ // Immediately returns ErrTimeout if the deadline has already been reached.
11701183//
11711184// ErrNoFreeConns is returned if all HostClient.MaxConns connections
11721185// to the host are busy.
@@ -1175,6 +1188,9 @@ func (c *HostClient) DoTimeout(req *Request, resp *Response, timeout time.Durati
11751188// and AcquireResponse in performance-critical code.
11761189func (c * HostClient ) DoDeadline (req * Request , resp * Response , deadline time.Time ) error {
11771190 req .timeout = time .Until (deadline )
1191+ if req .timeout < 0 {
1192+ return ErrTimeout
1193+ }
11781194 return c .Do (req , resp )
11791195}
11801196
0 commit comments