-
Notifications
You must be signed in to change notification settings - Fork 554
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(xrpc-server): properly parse & process content-encoding #2464
Conversation
ac67843
to
cf04e48
Compare
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.
Looks good!
2eaf59c
to
14dbb29
Compare
14dbb29
to
8cf9f1b
Compare
if (input?.body instanceof Readable) { | ||
// If the body stream errors at any time, abort the request | ||
input.body.once('error', next) | ||
} |
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.
This line breaks Express' flow control. Indeed, when the stream is being consumed, the consumer might will also catch that error. The consumer can then decide to do multiple things:
- call
next()
ornext(err)
- handle the error and write to the response
in any case, the error
listener here will not "abort" the request, but only trigger the next error middleware, and will cause that error middleware to be called while the body consumer might try to do stuff with the response.
finishFlush: zlib.constants.Z_SYNC_FLUSH, | ||
}) | ||
case 'deflate': | ||
return zlib.createInflate() |
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.
oh nice snag on switching that out
{ | ||
encoding: 'application/octet-stream', | ||
headers: { | ||
'content-encoding': 'gzip, identity, deflate, identity, br, identity', |
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.
wowee ✨
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.
looks great - super thorough 👌
content-encoding can contain multiple values (comma separated).
createDeflate
instead ofcreateInflate
to decompress bytes encoded using thedeflate
algo. This PR changes that.content-length
headers that are not a number. This PR ensures that the parsing of the number did not result inNaN
.