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

Refactor NoContentVerb into NoContentVerbWithStatus (#1532) #1550

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nbacquey
Copy link
Contributor

@nbacquey nbacquey commented Mar 3, 2022

There are several HTTP status codes that correspond to a response body with NoContent. This PR introduces NoContentVerbWithStatus which generalizes NoContentVerb to cases when the return status may be
different from 204. The former replaces the latter anywhere possible.
NoContentVerb is kept as a special case of NoContentVerbWithStatus for backwards compatibility.

This PR also adds a test case for NoContentVerbWithStatus in ServerSpec.hs

nbacquey added 3 commits March 3, 2022 17:00
…1532)

There are several HTTP status codes that correspond to a response body
with `NoContent`. This commit introduces `NoContentVerbWithStatus` which
generalizes `NoContentVerb` to cases when the return status may be
different from 204. The former replaces the latter anywhere possible.

`NoContentVerb` is kept as a special case of `NoContentVerbWithStatus`
for backwards compatibility.
-- | @NoContentVerbWithStatus@ is a specific type to represent 'NoContent' responses.
-- It does not require either a list of content types (because there's no content).
-- It still requires a status code, because several statuses may have no content.
-- (e.g. 204, 301, 302, or 303).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do have a philosophical question here: when using 30X status codes, the Location header must be set. We are not enforcing this here — and in fact, your test does not do that either.

Wouldn't it be better to provide redirect combinators that do enforce this constraint ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have two different problems here:

I think those issues should be addressed separately, unless maybe if the only other way to return NoContent is to have a 3xx status code, in which case we could kill two birds with one stone.
I may be mistaken, but I think NoContent could be returned in a number of other cases, for instance on endpoints that would be hardcoded to return 4xx errors.

I suggest we proceed with the PR as it is, then tackle the issue of Location headers separately.

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.

2 participants