Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor apiClientImpl.DoGetFallback #1021

Merged
merged 1 commit into from Apr 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 5 additions & 9 deletions api/prometheus/v1/api.go
Expand Up @@ -1133,27 +1133,23 @@ func (h *apiClientImpl) Do(ctx context.Context, req *http.Request) (*http.Respon
// DoGetFallback will attempt to do the request as-is, and on a 405 or 501 it
// will fallback to a GET request.
func (h *apiClientImpl) DoGetFallback(ctx context.Context, u *url.URL, args url.Values) (*http.Response, []byte, Warnings, error) {
req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(args.Encode()))
encodedArgs := args.Encode()
req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(encodedArgs))
if err != nil {
return nil, nil, nil, err
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")

resp, body, warnings, err := h.Do(ctx, req)
if resp != nil && (resp.StatusCode == http.StatusMethodNotAllowed || resp.StatusCode == http.StatusNotImplemented) {
u.RawQuery = args.Encode()
u.RawQuery = encodedArgs
req, err = http.NewRequest(http.MethodGet, u.String(), nil)
if err != nil {
return nil, nil, warnings, err
kakkoyun marked this conversation as resolved.
Show resolved Hide resolved
}

} else {
if err != nil {
return resp, body, warnings, err
}
return resp, body, warnings, nil
return h.Do(ctx, req)
}
return h.Do(ctx, req)
return resp, body, warnings, err
}

func formatTime(t time.Time) string {
Expand Down