Verbessere die URL-Bau-Logik im Client; stelle sicher, dass der Basis-Pfad nicht ersetzt wird, wenn der Dienst-Pfad absolut ist
This commit is contained in:
@@ -148,11 +148,16 @@ func WithUserAgent(ua string) Option {
|
|||||||
|
|
||||||
// do executes an HTTP request with retry logic.
|
// do executes an HTTP request with retry logic.
|
||||||
func (c *Client) do(ctx context.Context, method, path string, body, result interface{}) error {
|
func (c *Client) do(ctx context.Context, method, path string, body, result interface{}) error {
|
||||||
// Build full URL
|
// Build full URL by joining the base URL path with the service path.
|
||||||
u, err := c.baseURL.Parse(path)
|
// url.URL.Parse() is not used here because it would replace the base path
|
||||||
|
// when the service path is absolute (starts with "/").
|
||||||
|
refURL, err := url.Parse(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to parse path: %w", err)
|
return fmt.Errorf("failed to parse path: %w", err)
|
||||||
}
|
}
|
||||||
|
u := *c.baseURL
|
||||||
|
u.Path = strings.TrimRight(c.baseURL.Path, "/") + "/" + strings.TrimLeft(refURL.Path, "/")
|
||||||
|
u.RawQuery = refURL.RawQuery
|
||||||
|
|
||||||
// Serialize request body if present
|
// Serialize request body if present
|
||||||
var reqBody io.Reader
|
var reqBody io.Reader
|
||||||
|
|||||||
Reference in New Issue
Block a user