fix: fetching packument from AWS CodeArtifact (#9863)

close #9862
This commit is contained in:
Zoltan Kochan
2025-08-15 12:10:22 +02:00
committed by GitHub
parent c7f97a41f0
commit 87d3aa8bfc
3 changed files with 14 additions and 3 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/fetch": patch
"pnpm": patch
---
When making requests for the non-abbreviated packument, add `*/*` to the `Accept` header to avoid getting a 406 error on AWS CodeArtifact [#9862](https://github.com/pnpm/pnpm/issues/9862).

View File

@@ -164,6 +164,7 @@
"outfile",
"overrider",
"packlist",
"packument",
"paralleljs",
"parallelly",
"parseable",

View File

@@ -6,8 +6,12 @@ import { fetch, isRedirect, type Response, type RequestInfo, type RequestInit }
const USER_AGENT = 'pnpm' // or maybe make it `${pkg.name}/${pkg.version} (+https://npm.im/${pkg.name})`
const ABBREVIATED_DOC = 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*'
const JSON_DOC = 'application/json'
const FULL_DOC = 'application/json'
const ACCEPT_FULL_DOC = `${FULL_DOC}; q=1.0, */*`
const ABBREVIATED_DOC = 'application/vnd.npm.install-v1+json'
const ACCEPT_ABBREVIATED_DOC = `${ABBREVIATED_DOC}; q=1.0, ${FULL_DOC}; q=0.8, */*`
const MAX_FOLLOWED_REDIRECTS = 20
export interface FetchWithAgentOptions extends RequestInit {
@@ -102,7 +106,7 @@ function getHeaders (
}
): Headers {
const headers: { accept: string, authorization?: string, 'user-agent'?: string } = {
accept: opts.fullMetadata === true ? JSON_DOC : ABBREVIATED_DOC,
accept: opts.fullMetadata === true ? ACCEPT_FULL_DOC : ACCEPT_ABBREVIATED_DOC,
}
if (opts.auth) {
headers['authorization'] = opts.auth