-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
[Bug]: Empty Response with Content-Type: application/json Throws Error #11145
Comments
Thanks for the detailed writeup @SpencerDuball! Just to clarify a couple things:
I think it's reasonable for us to specifically look for |
Also a side note, just parsing for I will put this site back up to demonstrate the error in an actual environment later today, just got to office and don’t have my personal computer to deploy this one quick. Thanks for having a look at this issue! |
ok yeah I was originally worried about double-reading issues if using |
This is resolved by #11164 and should be available in the next release |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
What version of React Router are you using?
@remix-run+router@1.14.1
Steps to Reproduce
This is the
_index.tsx
page of a default Remix app. Clicking the button if running locally will trigger this issue. I have also included an example of theLink
component because the issue appears to exist in the same place on different hosting provider such as AWS CloudFront. In AWS CloudFront it appears that empty requests are sent back asContent-Type: application/json
which includes client-side navigation withLink
components.Expected Behavior
Issue Location
The issue comes from this line in the
@remix-run/router
package:react-router/packages/router/router.ts
Line 4101 in e4f663c
Proposed Solution
In this section, we are checking if the
Content-Type: application/json
exists, and then parsing for a JSON response. However, if the response body is null an error will be thrown. I believe adding a check forContent-Length: 0
before attempting to parse for JSON would be good.Reason For Solution
I have looked in RFC#7231 and RFC#2616 and the way this package is parsing for the
Content-Type: application/json
certainly is correct - however a bit of a blindspot in the RFCs is how to deal appropriately with Empty responses:Content-Type
headerContent-Length: 0
header value.Content-Type
value.The RFCs also indicate that the
Content-Type
is an optional field. It SHOULD be sent but is not required as the client may attempt to parse the payload format on it's own. In this issue I have highlighted where I am recieving an issue from AWS CloudFront which seems to be relying on checking theContent-Length: 0
header.For these reasons, I think it would be a good improvement to check the
Content-Length: 0
even though the current implementation is valid.Actual Behavior
Currently there is no check for an empty body before attempting to parse for JSON. Right now if the
Content-Type: application/json
header is sent then React Router/Remix will parse for JSON.The text was updated successfully, but these errors were encountered: