From e4e7bf5c8c47454f276e75773ef820c060cc3b5f Mon Sep 17 00:00:00 2001 From: ffalor <35144141+ffalor@users.noreply.github.com> Date: Thu, 1 Jun 2023 08:54:56 -0500 Subject: [PATCH] force method to uppercase (#7514) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mislav Marohnić --- pkg/cmd/api/http.go | 2 +- pkg/cmd/api/http_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/api/http.go b/pkg/cmd/api/http.go index 652d11d81..3d6bb240e 100644 --- a/pkg/cmd/api/http.go +++ b/pkg/cmd/api/http.go @@ -50,7 +50,7 @@ func httpRequest(client *http.Client, hostname string, method string, p string, return nil, fmt.Errorf("unrecognized parameters type: %v", params) } - req, err := http.NewRequest(method, requestURL, body) + req, err := http.NewRequest(strings.ToUpper(method), requestURL, body) if err != nil { return nil, err } diff --git a/pkg/cmd/api/http_test.go b/pkg/cmd/api/http_test.go index 11294a2e5..f63566490 100644 --- a/pkg/cmd/api/http_test.go +++ b/pkg/cmd/api/http_test.go @@ -129,6 +129,24 @@ func Test_httpRequest(t *testing.T) { headers: "", }, }, + { + name: "lowercase HTTP method", + args: args{ + client: &httpClient, + host: "github.com", + method: "get", + p: "repos/octocat/spoon-knife", + params: nil, + headers: []string{}, + }, + wantErr: false, + want: expects{ + method: "GET", + u: "https://api.github.com/repos/octocat/spoon-knife", + body: "", + headers: "", + }, + }, { name: "GET with leading slash", args: args{