Skip to content
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

content-length missing when set on header response #313

Closed
vlovich opened this issue Jul 15, 2022 · 4 comments
Closed

content-length missing when set on header response #313

vlovich opened this issue Jul 15, 2022 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@vlovich
Copy link
Contributor

vlovich commented Jul 15, 2022

If the user sets a content length in response to a HEAD request that content-length is sent to the eyeball. Under miniflare the content-length is stripped

@mrbbot
Copy link
Contributor

mrbbot commented Aug 11, 2022

Hey! 👋 I'm guessing this is coming from here:

if (headers["content-encoding"] && response.encodeBody === "auto") {
// Content-Length will be wrong as it's for the decoded length
delete headers["content-length"];
// Reverse of https://github.com/nodejs/undici/blob/48d9578f431cbbd6e74f77455ba92184f57096cf/lib/fetch/index.js#L1660
const codings = headers["content-encoding"]
.toString()
.toLowerCase()
.split(",")
.map((x) => x.trim());
for (const coding of codings) {
if (/(x-)?gzip/.test(coding)) {
encoders.push(zlib.createGzip());
} else if (/(x-)?deflate/.test(coding)) {
encoders.push(zlib.createDeflate());
} else if (coding === "br") {
encoders.push(zlib.createBrotliCompress());
} else {
// Unknown encoding, don't do any encoding at all
log?.warn(`Unknown encoding \"${coding}\", sending plain response...`);
encoders.length = 0;
break;
}
}
}

This header probably shouldn't be deleted unless some encoders are set, but even then, I think it's still the right thing to do with encodeBody set to auto? Let me know if I'm misunderstanding something.

@mrbbot mrbbot added the question Further information is requested label Aug 11, 2022
@vlovich
Copy link
Contributor Author

vlovich commented Aug 31, 2022

HEAD responses don't have a body so not sure how encodeBody is playing a role. Also, this behavior is not consistent with behavior in the runtime I think. On the other hand, it could be specific to R2 because we've configured FL to have standard-conforming behavior on our zone so that might be another source of difference. Not sure.

@vlovich
Copy link
Contributor Author

vlovich commented Aug 31, 2022

Actually, even our HEAD response has encodeBody: 'manual',

@vlovich
Copy link
Contributor Author

vlovich commented Aug 31, 2022

Also, the content-encoding we're setting isn't one of the supported ones so it seems weird to delete content length in that case.

@mrbbot mrbbot added bug Something isn't working and removed question Further information is requested labels Sep 1, 2022
@mrbbot mrbbot added this to the 2.8.0 milestone Sep 1, 2022
@mrbbot mrbbot closed this as completed in d4de3a6 Sep 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants