diff options
author | Igor Drozdov <idrozdov@gitlab.com> | 2022-08-03 16:19:50 +0200 |
---|---|---|
committer | Igor Drozdov <idrozdov@gitlab.com> | 2022-08-03 16:19:50 +0200 |
commit | d410fbdb0d450ee6807dac3e2ccde49df1498d5e (patch) | |
tree | 71703ab2db8de8f4abc4433bcbb5454da376a0c8 | |
parent | 8f2a4e90923a852eb386885b9379d5953fd8781b (diff) | |
download | gitlab-shell-id-try-different-mr.tar.gz |
Try changes from a different MRid-try-different-mr
-rw-r--r-- | client/client_test.go | 11 | ||||
-rw-r--r-- | client/gitlabnet.go | 6 |
2 files changed, 16 insertions, 1 deletions
diff --git a/client/client_test.go b/client/client_test.go index 37f7d3c..e91d3da 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -77,6 +77,7 @@ func TestClients(t *testing.T) { testAuthenticationHeader(t, client) testJWTAuthenticationHeader(t, client) testXForwardedForHeader(t, client) + testHostWithTrailingSlash(t, client) }) } } @@ -237,6 +238,16 @@ func testXForwardedForHeader(t *testing.T, client *GitlabNetClient) { }) } +func testHostWithTrailingSlash(t *testing.T, client *GitlabNetClient) { + oldHost := client.httpClient.Host + client.httpClient.Host = oldHost + "/" + + testSuccessfulGet(t, client) + testSuccessfulPost(t, client) + + client.httpClient.Host = oldHost +} + func buildRequests(t *testing.T, relativeURLRoot string) []testserver.TestRequestHandler { requests := []testserver.TestRequestHandler{ { diff --git a/client/gitlabnet.go b/client/gitlabnet.go index c34f148..a4f59d8 100644 --- a/client/gitlabnet.go +++ b/client/gitlabnet.go @@ -85,6 +85,10 @@ func normalizePath(path string) string { return path } +func appendPath(host string, path string) string { + return strings.TrimSuffix(host, "/") + "/" + strings.TrimPrefix(path, "/") +} + func newRequest(ctx context.Context, method, host, path string, data interface{}) (*http.Request, error) { var jsonReader io.Reader if data != nil { @@ -96,7 +100,7 @@ func newRequest(ctx context.Context, method, host, path string, data interface{} jsonReader = bytes.NewReader(jsonData) } - request, err := http.NewRequestWithContext(ctx, method, host+path, jsonReader) + request, err := http.NewRequestWithContext(ctx, method, appendPath(host, path), jsonReader) if err != nil { return nil, err } |