Skip to content

Commit

Permalink
fix: dont set _contentLength if not in headers (#368)
Browse files Browse the repository at this point in the history
The opposite of #366. This is not a change in behavior but makes it
clear that we don't expect _contentLength to be set when the request is
coming directly from the registry when there is no cache.
  • Loading branch information
lukekarrys committed May 6, 2024
1 parent 1b6950b commit 5e75582
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ class RegistryFetcher extends Fetcher {
integrity: null,
})
const packument = await res.json()
packument._contentLength = +res.headers.get('content-length')
const contentLength = res.headers.get('content-length')
if (contentLength) {
packument._contentLength = Number(contentLength)
}
this.packumentCache?.set(this.packumentUrl, packument)
return packument
} catch (err) {
Expand Down
6 changes: 6 additions & 0 deletions test/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -1341,3 +1341,9 @@ t.test('option replaceRegistryHost', rhTest => {

rhTest.end()
})

t.test('packument contentLength from registry', async t => {
const f = new RegistryFetcher('underscore', { registry, cache })
const p = await f.packument()
t.equal(p._contentLength, undefined, 'content length is undefined from registry requests')
})

0 comments on commit 5e75582

Please sign in to comment.