@@ -202,23 +202,17 @@ type clientConn struct {
202
202
203
203
// Do do a http request
204
204
func (c * FastHTTPClient ) Do (req * fasthttp.Request , addr string , option * HTTPOption ) (* fasthttp.Response , error ) {
205
- resp , retry , err := c .do (req , addr , option )
206
- if err != nil && retry && isIdempotent (req ) {
207
- resp , _ , err = c .do (req , addr , option )
208
- }
209
- if err == io .EOF {
210
- err = fasthttp .ErrConnectionClosed
211
- }
205
+ resp , err := c .do (req , addr , option )
212
206
return resp , err
213
207
}
214
208
215
- func (c * FastHTTPClient ) do (req * fasthttp.Request , addr string , option * HTTPOption ) (* fasthttp.Response , bool , error ) {
209
+ func (c * FastHTTPClient ) do (req * fasthttp.Request , addr string , option * HTTPOption ) (* fasthttp.Response , error ) {
216
210
resp := fasthttp .AcquireResponse ()
217
- ok , err := c .doNonNilReqResp (req , resp , addr , option )
218
- return resp , ok , err
211
+ err := c .doNonNilReqResp (req , resp , addr , option )
212
+ return resp , err
219
213
}
220
214
221
- func (c * FastHTTPClient ) doNonNilReqResp (req * fasthttp.Request , resp * fasthttp.Response , addr string , option * HTTPOption ) ( bool , error ) {
215
+ func (c * FastHTTPClient ) doNonNilReqResp (req * fasthttp.Request , resp * fasthttp.Response , addr string , option * HTTPOption ) error {
222
216
if req == nil {
223
217
panic ("BUG: req cannot be nil" )
224
218
}
@@ -248,7 +242,7 @@ func (c *FastHTTPClient) doNonNilReqResp(req *fasthttp.Request, resp *fasthttp.R
248
242
249
243
cc , err := hc .acquireConn (addr )
250
244
if err != nil {
251
- return false , err
245
+ return err
252
246
}
253
247
conn := cc .c
254
248
@@ -258,13 +252,11 @@ func (c *FastHTTPClient) doNonNilReqResp(req *fasthttp.Request, resp *fasthttp.R
258
252
// of the last write deadline exceeded.
259
253
// See https://github.com/golang/go/issues/15133 for details.
260
254
currentTime := time .Now ()
261
- if currentTime .Sub (cc .lastWriteDeadlineTime ) > (opt .WriteTimeout >> 2 ) {
262
- if err = conn .SetWriteDeadline (currentTime .Add (opt .WriteTimeout )); err != nil {
263
- hc .closeConn (cc )
264
- return true , err
265
- }
266
- cc .lastWriteDeadlineTime = currentTime
255
+ if err = conn .SetWriteDeadline (currentTime .Add (opt .WriteTimeout )); err != nil {
256
+ hc .closeConn (cc )
257
+ return err
267
258
}
259
+ cc .lastWriteDeadlineTime = currentTime
268
260
}
269
261
270
262
resetConnection := false
@@ -286,7 +278,7 @@ func (c *FastHTTPClient) doNonNilReqResp(req *fasthttp.Request, resp *fasthttp.R
286
278
if err != nil {
287
279
c .releaseWriter (bw )
288
280
hc .closeConn (cc )
289
- return true , err
281
+ return err
290
282
}
291
283
c .releaseWriter (bw )
292
284
@@ -296,13 +288,11 @@ func (c *FastHTTPClient) doNonNilReqResp(req *fasthttp.Request, resp *fasthttp.R
296
288
// of the last read deadline exceeded.
297
289
// See https://github.com/golang/go/issues/15133 for details.
298
290
currentTime := time .Now ()
299
- if currentTime .Sub (cc .lastReadDeadlineTime ) > (opt .ReadTimeout >> 2 ) {
300
- if err = conn .SetReadDeadline (currentTime .Add (opt .ReadTimeout )); err != nil {
301
- hc .closeConn (cc )
302
- return true , err
303
- }
304
- cc .lastReadDeadlineTime = currentTime
291
+ if err = conn .SetReadDeadline (currentTime .Add (opt .ReadTimeout )); err != nil {
292
+ hc .closeConn (cc )
293
+ return err
305
294
}
295
+ cc .lastReadDeadlineTime = currentTime
306
296
}
307
297
308
298
if ! req .Header .IsGet () && req .Header .IsHead () {
@@ -314,9 +304,9 @@ func (c *FastHTTPClient) doNonNilReqResp(req *fasthttp.Request, resp *fasthttp.R
314
304
c .releaseReader (br )
315
305
hc .closeConn (cc )
316
306
if err == io .EOF {
317
- return true , err
307
+ return err
318
308
}
319
- return false , err
309
+ return err
320
310
}
321
311
c .releaseReader (br )
322
312
@@ -326,7 +316,7 @@ func (c *FastHTTPClient) doNonNilReqResp(req *fasthttp.Request, resp *fasthttp.R
326
316
hc .releaseConn (cc )
327
317
}
328
318
329
- return false , err
319
+ return err
330
320
}
331
321
332
322
func dialAddr (addr string ) (net.Conn , error ) {
@@ -369,10 +359,6 @@ func (c *FastHTTPClient) releaseReader(br *bufio.Reader) {
369
359
c .readerPool .Put (br )
370
360
}
371
361
372
- func isIdempotent (req * fasthttp.Request ) bool {
373
- return req .Header .IsGet () || req .Header .IsHead () || req .Header .IsPut ()
374
- }
375
-
376
362
func acquireClientConn (conn net.Conn ) * clientConn {
377
363
v := clientConnPool .Get ()
378
364
if v == nil {
0 commit comments