Skip to content

Commit 1c0c88a

Browse files
committed
fix(proxy.go): ensure proper URL construction by adding missing slashes between base URL and path to prevent request errors
refactor(proxy.go): handle empty proxy path case to construct testPath relative to base URL for improved path management
1 parent 0772adc commit 1c0c88a

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

pkg/proxy/proxy.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,15 @@ func (p *Proxy) probePath(ctx context.Context, url *url.URL, location string) (i
460460
},
461461
}
462462

463-
req, err := http.NewRequestWithContext(ctx, http.MethodHead, url.String()+location, nil)
463+
// Construct URL properly: ensure / separator between base URL and path
464+
baseURL := url.String()
465+
if !strings.HasSuffix(baseURL, "/") && !strings.HasPrefix(location, "/") {
466+
baseURL = baseURL + "/"
467+
}
468+
fullURL := baseURL + location
469+
req, err := http.NewRequestWithContext(ctx, http.MethodHead, fullURL, nil)
464470
if err != nil {
465-
otelzap.L().WithError(err).Ctx(ctx).Error("failed to create request", zap.String("url", url.String()+location), zap.String("http.method", http.MethodHead))
471+
otelzap.L().WithError(err).Ctx(ctx).Error("failed to create request", zap.String("url", fullURL), zap.String("http.method", http.MethodHead))
466472
return http.StatusInternalServerError, err
467473
}
468474

@@ -519,7 +525,13 @@ func (p *Proxy) lookupPath(ctx context.Context, page *config.Page, sourceHost st
519525

520526
cacheKey := fmt.Sprintf("%s-%s-%s", sourceHost, targetPath, lookup)
521527
_, _ = p.group.Do(cacheKey, func() (interface{}, error) {
522-
testPath := path.Clean(fmt.Sprintf("/%s/%s", targetPath, lookup))
528+
var testPath string
529+
if page.Proxy.Path.String() == "" {
530+
// When proxy path is empty, don't add leading / - construct path relative to base URL
531+
testPath = path.Join(targetPath, lookup)
532+
} else {
533+
testPath = path.Clean(fmt.Sprintf("/%s/%s", targetPath, lookup))
534+
}
523535
statusCode, err := p.probePath(probeCtx, backendURL, testPath)
524536
if err != nil {
525537
return nil, humane.Wrap(err, "Unable to probe path", "Make sure the path exists and is accessible.")

0 commit comments

Comments
 (0)