Skip to content

Commit 130da3b

Browse files
authored
Merge pull request #1021 from dohnto/dohnto/line-of-sight
Refactor apiClientImpl.DoGetFallback
2 parents 3e9269d + 40e54a7 commit 130da3b

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

api/prometheus/v1/api.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,27 +1133,23 @@ func (h *apiClientImpl) Do(ctx context.Context, req *http.Request) (*http.Respon
11331133
// DoGetFallback will attempt to do the request as-is, and on a 405 or 501 it
11341134
// will fallback to a GET request.
11351135
func (h *apiClientImpl) DoGetFallback(ctx context.Context, u *url.URL, args url.Values) (*http.Response, []byte, Warnings, error) {
1136-
req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(args.Encode()))
1136+
encodedArgs := args.Encode()
1137+
req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(encodedArgs))
11371138
if err != nil {
11381139
return nil, nil, nil, err
11391140
}
11401141
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
11411142

11421143
resp, body, warnings, err := h.Do(ctx, req)
11431144
if resp != nil && (resp.StatusCode == http.StatusMethodNotAllowed || resp.StatusCode == http.StatusNotImplemented) {
1144-
u.RawQuery = args.Encode()
1145+
u.RawQuery = encodedArgs
11451146
req, err = http.NewRequest(http.MethodGet, u.String(), nil)
11461147
if err != nil {
11471148
return nil, nil, warnings, err
11481149
}
1149-
1150-
} else {
1151-
if err != nil {
1152-
return resp, body, warnings, err
1153-
}
1154-
return resp, body, warnings, nil
1150+
return h.Do(ctx, req)
11551151
}
1156-
return h.Do(ctx, req)
1152+
return resp, body, warnings, err
11571153
}
11581154

11591155
func formatTime(t time.Time) string {

0 commit comments

Comments
 (0)