diff --git a/.changeset/odd-trams-make.md b/.changeset/odd-trams-make.md new file mode 100644 index 0000000000..2bad8c8a98 --- /dev/null +++ b/.changeset/odd-trams-make.md @@ -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). diff --git a/cspell.json b/cspell.json index 3c5a4a0b5f..0fc022649b 100644 --- a/cspell.json +++ b/cspell.json @@ -164,6 +164,7 @@ "outfile", "overrider", "packlist", + "packument", "paralleljs", "parallelly", "parseable", diff --git a/network/fetch/src/fetchFromRegistry.ts b/network/fetch/src/fetchFromRegistry.ts index 733313603a..3f23b5814f 100644 --- a/network/fetch/src/fetchFromRegistry.ts +++ b/network/fetch/src/fetchFromRegistry.ts @@ -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