@@ -16,6 +16,14 @@ import (
16
16
"time"
17
17
)
18
18
19
+ const (
20
+ methodDo = "Do"
21
+ methodGet = "Get"
22
+ methodHead = "Head"
23
+ methodPost = "Post"
24
+ methodPostForm = "PostForm"
25
+ )
26
+
19
27
//ErrUnexpectedMethod occurs when an http.Client method is unable to be mapped from a calling method in the pester client
20
28
var ErrUnexpectedMethod = errors .New ("unexpected client method, must be one of Do, Get, Head, Post, or PostFrom" )
21
29
@@ -196,7 +204,7 @@ func (c *Client) pester(p params) (*http.Response, error) {
196
204
// of concurrency. Other verbs can mutate and should not
197
205
// make use of the concurrency feature
198
206
concurrency := c .Concurrency
199
- if p .verb != "GET" {
207
+ if p .verb != http . MethodGet {
200
208
concurrency = 1
201
209
}
202
210
@@ -269,15 +277,15 @@ func (c *Client) pester(p params) (*http.Response, error) {
269
277
var resp * http.Response
270
278
// route the calls
271
279
switch p .method {
272
- case "Do" :
280
+ case methodDo :
273
281
resp , err = httpClient .Do (p .req )
274
- case "Get" :
282
+ case methodGet :
275
283
resp , err = httpClient .Get (p .url )
276
- case "Head" :
284
+ case methodHead :
277
285
resp , err = httpClient .Head (p .url )
278
- case "Post" :
286
+ case methodPost :
279
287
resp , err = httpClient .Post (p .url , p .bodyType , p .body )
280
- case "PostForm" :
288
+ case methodPostForm :
281
289
resp , err = httpClient .PostForm (p .url , p .data )
282
290
default :
283
291
err = ErrUnexpectedMethod
@@ -286,7 +294,7 @@ func (c *Client) pester(p params) (*http.Response, error) {
286
294
// Early return if we have a valid result
287
295
// Only retry (ie, continue the loop) on 5xx status codes and 429
288
296
289
- if err == nil && resp .StatusCode < 500 && (resp .StatusCode != 429 || (resp .StatusCode == 429 && ! c .RetryOnHTTP429 )) {
297
+ if err == nil && resp .StatusCode < http . StatusInternalServerError && (resp .StatusCode != http . StatusTooManyRequests || (resp .StatusCode == http . StatusTooManyRequests && ! c .RetryOnHTTP429 )) {
290
298
multiplexCh <- result {resp : resp , err : err , req : n , retry : i }
291
299
return
292
300
}
@@ -417,27 +425,27 @@ func (c *Client) log(ctx context.Context, e ErrEntry) {
417
425
418
426
// Do provides the same functionality as http.Client.Do
419
427
func (c * Client ) Do (req * http.Request ) (resp * http.Response , err error ) {
420
- return c .pester (params {method : "Do" , req : req , verb : req .Method , url : req .URL .String ()})
428
+ return c .pester (params {method : methodDo , req : req , verb : req .Method , url : req .URL .String ()})
421
429
}
422
430
423
431
// Get provides the same functionality as http.Client.Get
424
432
func (c * Client ) Get (url string ) (resp * http.Response , err error ) {
425
- return c .pester (params {method : "Get" , url : url , verb : "GET" })
433
+ return c .pester (params {method : methodGet , url : url , verb : http . MethodGet })
426
434
}
427
435
428
436
// Head provides the same functionality as http.Client.Head
429
437
func (c * Client ) Head (url string ) (resp * http.Response , err error ) {
430
- return c .pester (params {method : "Head" , url : url , verb : "HEAD" })
438
+ return c .pester (params {method : methodHead , url : url , verb : http . MethodHead })
431
439
}
432
440
433
441
// Post provides the same functionality as http.Client.Post
434
442
func (c * Client ) Post (url string , bodyType string , body io.Reader ) (resp * http.Response , err error ) {
435
- return c .pester (params {method : "Post" , url : url , bodyType : bodyType , body : body , verb : "POST" })
443
+ return c .pester (params {method : methodPost , url : url , bodyType : bodyType , body : body , verb : http . MethodPost })
436
444
}
437
445
438
446
// PostForm provides the same functionality as http.Client.PostForm
439
447
func (c * Client ) PostForm (url string , data url.Values ) (resp * http.Response , err error ) {
440
- return c .pester (params {method : "PostForm" , url : url , data : data , verb : "POST" })
448
+ return c .pester (params {method : methodPostForm , url : url , data : data , verb : http . MethodPost })
441
449
}
442
450
443
451
// set RetryOnHTTP429 for clients,
0 commit comments