File tree Expand file tree Collapse file tree 3 files changed +25
-4
lines changed Expand file tree Collapse file tree 3 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ func main() {
35
35
r .HandleFunc ("/pagination/cursor" , pagination .HandleCursor ).Methods (http .MethodGet , http .MethodPut )
36
36
r .HandleFunc ("/pagination/url" , pagination .HandleURL ).Methods (http .MethodGet )
37
37
r .HandleFunc ("/retries" , retries .HandleRetries ).Methods (http .MethodGet , http .MethodPost )
38
+ r .HandleFunc ("/retries/after" , retries .HandleRetries ).Methods (http .MethodGet )
38
39
r .HandleFunc ("/errors/{status_code}" , errors .HandleErrors ).Methods (http .MethodGet )
39
40
r .HandleFunc ("/optional" , acceptHeaders .HandleAcceptHeaderMultiplexing ).Methods (http .MethodGet )
40
41
r .HandleFunc ("/readonlyorwriteonly" , readonlywriteonly .HandleReadOrWrite ).Methods (http .MethodPost )
Original file line number Diff line number Diff line change @@ -120,6 +120,7 @@ func HandleCursor(w http.ResponseWriter, r *http.Request) {
120
120
121
121
func HandleURL (w http.ResponseWriter , r * http.Request ) {
122
122
attemptsString := r .FormValue ("attempts" )
123
+ isReferencePath := r .FormValue ("is-reference-path" )
123
124
var attempts int
124
125
if attemptsString != "" {
125
126
var err error
@@ -137,9 +138,15 @@ func HandleURL(w http.ResponseWriter, r *http.Request) {
137
138
}
138
139
139
140
if attempts > 1 {
140
- baseURL := fmt .Sprintf ("%s://%s%s " , r .URL .Scheme , r .Host , r . URL . Path )
141
+ baseURL := fmt .Sprintf ("%s://%s" , r .URL .Scheme , r .Host )
141
142
if r .URL .Scheme == "" { // Fallback if Scheme is not available
142
- baseURL = fmt .Sprintf ("http://%s%s" , r .Host , r .URL .Path )
143
+ baseURL = fmt .Sprintf ("http://%s" , r .Host )
144
+ }
145
+
146
+ if isReferencePath == "true" {
147
+ baseURL = r .URL .Path
148
+ } else {
149
+ baseURL = fmt .Sprintf ("%s%s" , baseURL , r .URL .Path )
143
150
}
144
151
145
152
nextUrl := fmt .Sprintf ("%s?attempts=%d" , baseURL , attempts - 1 )
Original file line number Diff line number Diff line change @@ -15,6 +15,18 @@ type retriesResponse struct {
15
15
func HandleRetries (w http.ResponseWriter , r * http.Request ) {
16
16
requestID := r .URL .Query ().Get ("request-id" )
17
17
numRetriesStr := r .URL .Query ().Get ("num-retries" )
18
+ retryAfterVal := r .URL .Query ().Get ("retry-after-val" )
19
+
20
+ retryAfter := 0
21
+ if retryAfterVal != "" {
22
+ var err error
23
+ retryAfter , err = strconv .Atoi (retryAfterVal )
24
+ if err != nil {
25
+ w .WriteHeader (http .StatusBadRequest )
26
+ _ , _ = w .Write ([]byte ("retry-after-val must be an integer" ))
27
+ return
28
+ }
29
+ }
18
30
19
31
numRetries := 3
20
32
if numRetriesStr != "" {
@@ -40,8 +52,9 @@ func HandleRetries(w http.ResponseWriter, r *http.Request) {
40
52
callCounts [requestID ]++
41
53
42
54
if callCounts [requestID ] < numRetries {
43
- // sets a static one second retry after timeout, the client will decide whether or not to respect it
44
- w .Header ().Set ("Retry-After" , "1" )
55
+ if retryAfter > 0 {
56
+ w .Header ().Set ("Retry-After" , strconv .Itoa (retryAfter ))
57
+ }
45
58
w .WriteHeader (http .StatusServiceUnavailable )
46
59
_ , _ = w .Write ([]byte ("request failed please retry" ))
47
60
return
You can’t perform that action at this time.
0 commit comments