Skip to content

Commit aa5fbb8

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

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
@@ -27,14 +27,15 @@ type RequestOption = requestconfig.RequestOption
2727
// For security reasons, ensure that the base URL is trusted.
2828
func WithBaseURL(base string) RequestOption {
2929
u, err := url.Parse(base)
30+
if err == nil && u.Path != "" && !strings.HasSuffix(u.Path, "/") {
31+
u.Path += "/"
32+
}
33+
3034
return requestconfig.RequestOptionFunc(func(r *requestconfig.RequestConfig) error {
3135
if err != nil {
32-
return fmt.Errorf("requestoption: WithBaseURL failed to parse url %s\n", err)
36+
return fmt.Errorf("requestoption: WithBaseURL failed to parse url %s", err)
3337
}
3438

35-
if u.Path != "" && !strings.HasSuffix(u.Path, "/") {
36-
u.Path += "/"
37-
}
3839
r.BaseURL = u
3940
return nil
4041
})

0 commit comments

Comments
 (0)