Repository navigation
Conversation
…ent-Encoding Next 16.4.5 strips content-encoding, content-length and transfer-encoding from every route-handler Response in sendResponse, so the gzip compress.ts applied reached clients unlabelled, and Next's own compression skips route handlers. forward() now relays the body as fetch decoded it. Cloudflare compresses responses in front of production. A forward() test runs against a gzipping upstream with and without Accept-Encoding, loading the server module through resolve hooks in src/lib/test. Closes #128
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Next 16.4.5, on dev since #120, strips
content-encoding,content-lengthandtransfer-encodingfrom every route-handlerResponseinsendResponse(next/dist/server/send-response.js; 16.4.4 has no such filter).src/lib/proxy/compress.tsgzipped relayed bodies and labelled them, so the bytes reached clients unlabelled and any client that accepts gzip, Node'sfetchincluded, failed to parse the JSON. Next's own compression cannot take over:sendResponsecopies headers withappendHeader, which storesContent-Typeas an array, and the compression middleware skips a non-string type, so even/sitemap.xmlgoes out uncompressed.The proxy therefore stops encoding bodies.
compress.tsand its test are deleted, andforward()relays the body asfetchdecoded it. Cloudflare compresses responses in front of production; staging'srun.apphost has no Cloudflare and serves the API uncompressed. Clients see chunked responses with noContent-Length, which Next strips whatever the proxy does.mainis still on Next 16.3.0, so production is unaffected until the next release.forward()reads the first chunk of every body except event streams and/mcpbefore the response goes out, so a body that fails before its first byte still gets a logged 502 problem document, as it did on the gzip path. Everything after the first chunk streams unread.src/lib/proxy/test/forward.test.tsrunsforward()against a local upstream that gzips: with and withoutAccept-Encoding: gzipthe client gets noContent-Encodingand the decoded bytes; a body that fails before its first byte gets the 502; one that fails later gets a 200 whose body errors; an event stream reaches the client before the upstream ends.forward()importsserver-only,@/paths and extensionless modules, so the test loads it through resolve hooks insrc/lib/test/serverModules.ts, registered withmodule.register. Once@types/nodeis at 22 or later,module.registerHookscan replace the two files with one call.Closes #128
Testing:
pnpm lint,pnpm lint:css,pnpm typecheck,pnpm test(2267 pass),pnpm build. The gzip and 502 tests fail on dev. On the built standalone server with a gzipping fake upstream,/api/v1/graph/schemaand/openapi.jsonreturn plain JSON with noContent-Encoding, with and withoutAccept-Encoding: gzip, and Nodefetchparses both.scripts/share-migration-round-trip.tspasses on a build of this branch against the seeded dfo-apis local stack with noAccept-Encodingoverride, and proxied/api/v1/datasetsresponses arrive as plain JSON.