Skip to content

Commit 15e7e01

Browse files
Carlos YuIgor Drozdov
authored andcommitted
Fixed extra slashes in API request paths generated for geo
1 parent 8f2a4e9 commit 15e7e01

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

client/client_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func TestClients(t *testing.T) {
7777
testAuthenticationHeader(t, client)
7878
testJWTAuthenticationHeader(t, client)
7979
testXForwardedForHeader(t, client)
80+
testHostWithTrailingSlash(t, client)
8081
})
8182
}
8283
}
@@ -237,6 +238,16 @@ func testXForwardedForHeader(t *testing.T, client *GitlabNetClient) {
237238
})
238239
}
239240

241+
func testHostWithTrailingSlash(t *testing.T, client *GitlabNetClient) {
242+
oldHost := client.httpClient.Host
243+
client.httpClient.Host = oldHost + "/"
244+
245+
testSuccessfulGet(t, client)
246+
testSuccessfulPost(t, client)
247+
248+
client.httpClient.Host = oldHost
249+
}
250+
240251
func buildRequests(t *testing.T, relativeURLRoot string) []testserver.TestRequestHandler {
241252
requests := []testserver.TestRequestHandler{
242253
{

client/gitlabnet.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ func normalizePath(path string) string {
8585
return path
8686
}
8787

88+
func appendPath(host string, path string) string {
89+
return strings.TrimSuffix(host, "/") + "/" + strings.TrimPrefix(path, "/")
90+
}
91+
8892
func newRequest(ctx context.Context, method, host, path string, data interface{}) (*http.Request, error) {
8993
var jsonReader io.Reader
9094
if data != nil {
@@ -96,7 +100,7 @@ func newRequest(ctx context.Context, method, host, path string, data interface{}
96100
jsonReader = bytes.NewReader(jsonData)
97101
}
98102

99-
request, err := http.NewRequestWithContext(ctx, method, host+path, jsonReader)
103+
request, err := http.NewRequestWithContext(ctx, method, appendPath(host, path), jsonReader)
100104
if err != nil {
101105
return nil, err
102106
}

0 commit comments

Comments
 (0)