fix: fix response binary content handling #526
Merged
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.
Hey,
First of all, thanks for the project, it's really great.
We found a bug while upgrading to v3, concerning binary content.
It seems that the handling of binary content as response is broken. In
convertRes
, theparseHeaders
function simply stores headers in aRecord<string, string>
but doesn't take in account the Uppercase / Lowercase thing that we can found in headers. In our case, the headers received are likeContent-Type
but in the code, it compares to lowercaseheaders["content-type"]
. (Our infra uses lambdas + ApiGateway on top of that like mentioned in the docs)Here is a small NextJS API route that reproduce the problem in our case.
While reaching on browser the route, you should get an error that saying that the navigator can't display the image since it contains errors.
Second problem, which is more specific, is that we use on some routes pre-gzipped content. For example, our
sitemap.xml
is a pre-gzipped API route. In this case, the headerContent-Encoding
is already present and the response should take in account the header and be base64encoded for binary content.I also have simplified the check for
isBinaryContentType(headers["content-type"])
sinceparseHeaders
returns aRecord<string, string>
.Thanks