Skip to content

Commit 7ee7fb2

Browse files
fix(client): process custom base url ahead of time
1 parent f5753e4 commit 7ee7fb2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

option/requestoption.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ func WithAPIVersion(value string) RequestOption {
3737
// For security reasons, ensure that the base URL is trusted.
3838
func WithBaseURL(base string) RequestOption {
3939
u, err := url.Parse(base)
40+
if err == nil && u.Path != "" && !strings.HasSuffix(u.Path, "/") {
41+
u.Path += "/"
42+
}
43+
4044
return requestconfig.RequestOptionFunc(func(r *requestconfig.RequestConfig) error {
4145
if err != nil {
42-
return fmt.Errorf("requestoption: WithBaseURL failed to parse url %s\n", err)
46+
return fmt.Errorf("requestoption: WithBaseURL failed to parse url %s", err)
4347
}
4448

45-
if u.Path != "" && !strings.HasSuffix(u.Path, "/") {
46-
u.Path += "/"
47-
}
4849
r.BaseURL = u
4950
return nil
5051
})

0 commit comments

Comments
 (0)