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

check body length instead of 304 code to determine there is no body #399

Closed

Conversation

amir-arad
Copy link

@amir-arad amir-arad commented Jan 9, 2019

there are many scenarios where a response should have no body (302 is what I've encountered, but there are more).
current behavior is to check for 304 status, I suggest checking the body's length is simpler, covers more real life scenarios (like 200 with no body, it happens some times).

@amir-arad amir-arad force-pushed the handle-no-body-gracefully branch from e419334 to de00029 Compare January 9, 2019 09:29
@raphaeleidus
Copy link
Contributor

This removes functionality, just because the original request had no content doesn't mean that the proxy cannot return content.
If you proxy a 200 with no content the userResDecorator function can be used to provide content. Similarly a 500 with no content the method can be used to insert your own markup for an error. This PR would remove that ability.

304 is one of the only status codes where you are not allowed to provide a response body.

@monkpow
Copy link
Collaborator

monkpow commented Mar 7, 2019

Hrm. There was a lot of discussion on this on issue #251.

The original intent was to prevent authors from having to deal with an unexpectedly null body in the decorator. I think the thought at the time was "If there's no body, there's nothing to decorate."

I think @amir-arad solution is in line with this original intent -- it just expands and is more explicit about why it's skipping.

@raphaeleidus line of thinking is also interesting. I'm inclined to update the docs to indicate that an author has to be prepared for empty/null body. This would preserve the functionality that allows the decorator to add a body on a body-less proxy response.

I think in this case, I'd continue to keep the 304 guard because a body can't be added, and this is efficient to skip the test.

Thanks both for contributing. Let me consider this.

@monkpow
Copy link
Collaborator

monkpow commented Mar 11, 2019

@amir-arad Thanks for the positive conversation about this feature. Based on discussion on #408 I'm gonna close this one for now. Feel free to re-open if you want to continue the conversation.

@monkpow monkpow closed this Mar 11, 2019
monkpow pushed a commit that referenced this pull request Mar 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants