Skip to content

[Node.js] Follow HTTP 3xx redirects in onnxruntime-node install scripts#28618

Open
adityasingh2400 wants to merge 1 commit into
microsoft:mainfrom
adityasingh2400:fix-node-install-utils-follow-redirects-28265
Open

[Node.js] Follow HTTP 3xx redirects in onnxruntime-node install scripts#28618
adityasingh2400 wants to merge 1 commit into
microsoft:mainfrom
adityasingh2400:fix-node-install-utils-follow-redirects-28265

Conversation

@adityasingh2400
Copy link
Copy Markdown

Description

js/node/script/install-utils.js previously treated any non-200 response as a fatal error, so an HTTP 301/302/303/307/308 redirect on a metadata or artifact URL aborted npm install onnxruntime-node with messages like:

Error: Failed to download build list. HTTP status code = 302

The NuGet Server API documents that requests may return 301/302 and clients are expected to follow the Location header. This is currently being observed in the wild against https://api.nuget.org/v3/index.json, which 302s to a regional mirror.

Fix

Both downloadFile() and downloadJson() now:

  • detect 301/302/303/307/308 with a non-empty Location header,
  • resolve the next URL via new URL(res.headers.location, currentUrl) (handles both absolute and relative Location values),
  • recurse through an inner doRequest(currentUrl, redirectsLeft) helper,
  • cap redirect depth at 5 and surface a clear error if the cap is exceeded.

Existing 200 / 4xx / non-redirect-non-200 paths are unchanged, so no other behavior regresses.

Motivation and Context

Fixes #28265
Fixes #28393

Both reporters independently observed the same root cause (Linux/WSL2 hitting a 302 from the NuGet index endpoint) and proposed essentially the same fix. This PR implements it.

js/node/script/install-utils.js previously treated any non-200 response
as a fatal error, including 301/302/303/307/308 redirects. When the
NuGet release host returns a 302 to the actual artifact (recent
behavior), 'npm install onnxruntime-node' fails outright. Resolve the
Location header against the current URL and recurse, capped at five
redirects to avoid loops.

Fixes microsoft#28265
Fixes microsoft#28393
@adityasingh2400
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant