fix(proxy): keep package names that start with the registry name

The app mounts each handler behind http.StripPrefix. The npm and PyPI
handlers trimmed the registry prefix a second time. A request for
npm-run-all reached upstream as -run-all, and the npm package itself
became an empty path. PyPI trimmed /simple without a segment check.
This commit is contained in:
2026-11-24 00:22:49 +00:00
parent 30ebfaae3e
commit 916e2b0aa5
3 changed files with 39 additions and 4 deletions
+5 -3
View File
@@ -111,9 +111,11 @@ func New(cacheManager *cache.Manager, client *network.Client, config Config) *Ha
// ServeHTTP handles PyPI Simple API requests
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
path := strings.TrimPrefix(r.URL.Path, "/pypi")
// Also trim /simple prefix since upstream already includes it
path = strings.TrimPrefix(path, "/simple")
path := r.URL.Path
// Upstream already includes /simple; trim it only as a whole segment so a package such as simple-x keeps its name.
if path == "/simple" || strings.HasPrefix(path, "/simple/") {
path = path[len("/simple"):]
}
log.Debug().Str("path", path).Str("method", r.Method).Msg("PyPI proxy request")