-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: wait for size event from body for contentLength #366
Conversation
@@ -96,7 +98,11 @@ class RegistryFetcher extends Fetcher { | |||
integrity: null, | |||
}) | |||
const packument = await res.json() | |||
packument._contentLength = +res.headers.get('content-length') | |||
let contentLength = res.headers.get('content-length') ?? null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this ??
effectively the same test as isStream
? Do we really need them both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One take-it-or-leave-it question.
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.
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.
Closing in favor of #368. We don't want to wait for the entire stream to be decompressed and get the size event before moving on here. We could potentially Instead #368 makes it clear we won't get a contentLength from the registry, so we won't cache those in-memory since we can't be sure of their size. |
By default the
Accept-Encoding
request header is set togzip,deflate
which makes it so we don't get back aContent-Length
response header from the registry. Butnpm-registry-fetch
sets up asize
event on the response body that we can wait for before continuing if we don't get aContent-Length
header.This fixes the content length issue in #7463 for me when testing locally, but I need to run some more CLI tests with this linked to see if there are any adverse effects.