Skip to content

Never send Content-Length for 204#1294

Merged
lepture merged 1 commit intopallets:masterfrom
ikonst:fix-204
May 13, 2018
Merged

Never send Content-Length for 204#1294
lepture merged 1 commit intopallets:masterfrom
ikonst:fix-204

Conversation

@ikonst
Copy link
Copy Markdown
Contributor

@ikonst ikonst commented May 13, 2018

With flask-restful, it's easy to make a malformed response by doing return '', 204 or return None, 204. It might be idiomatic, but it would result in a 204 response with a non-empty body (containing a JSON payload such as '' or null).

We used to reset the Content-Length to 0 for status code 204, but since 1c70c3e we keep Content-Length: N while the body is eliminated (see BaseResponse.get_app_iter). This broke existing flask-restful applications:
flask-restful/flask-restful#736

Per section 3.3.2 of RFC 7230, "a server MUST NOT send a Content-Length header field in any response with a status code of 1xx (Informational) or 204 (No Content)". This change enforces it in get_wsgi_headers.

@lepture
Copy link
Copy Markdown
Contributor

lepture commented May 13, 2018

@lepture lepture merged commit e378a8f into pallets:master May 13, 2018
@ikonst ikonst deleted the fix-204 branch May 13, 2018 05:25
@randyesq
Copy link
Copy Markdown

What version did this fix get released to?

@ikonst
Copy link
Copy Markdown
Contributor Author

ikonst commented Oct 30, 2018

@randyesq still waiting for this to be released. The relevant issue has been locked by the project maintainer:
#1296

@davidism davidism added this to the 0.15 milestone Dec 9, 2018
davidism added a commit that referenced this pull request Dec 10, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants