Skip to content

Conversation

@digitalresistor
Copy link
Member

This is a follow-up to #166 and fixes the issue presented in #197.

This goes a step further than just making sure waitress doesn't generate any extra headers/content, it also removes it even if the application sent data it shouldn't have. This will help make sure that message bodies are not accidentally sent with HTTP status codes that SHOULD NOT contain message bodies.

Closes #197

This is used to test if a response should have a message body or not.
1xx, 204 and 304 should not have message bodies.
For responses that should not include a message body, we now explicitly
ignore the body from the application and no longer send it on to the
requesting client.

We also log a warning to let developers/users know.
content_length_header = headerval
else:
del response_headers[i]
continue # pragma: no cover
Copy link
Member

Choose a reason for hiding this comment

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

deletion while iteration - sure this is ok?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess I need to find out if enumerate creates a copy of the list or if it iterates over the list internally.

Copy link
Member Author

Choose a reason for hiding this comment

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

This will break in subtle ways if there is more than one Content-Length header set (which is illegal, but possible)

Copy link
Member

Choose a reason for hiding this comment

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

FWIW, enumerate has generator semantics (see PEP 279).

Copy link
Member Author

Choose a reason for hiding this comment

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

Then the other code and this code are both subtly broken... will fix

We don't want to delete items from a list while iterating over the list.
if not date_header:
response_headers.append(('Date', build_http_date(self.start_time)))

self.response_headers = response_headers
Copy link
Member Author

Choose a reason for hiding this comment

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

Not strictly required in this function, but required for testing.

@digitalresistor digitalresistor merged commit 4ce8f82 into master Sep 6, 2018
@digitalresistor digitalresistor deleted the body-less-304 branch September 6, 2018 04:42
digitalresistor added a commit that referenced this pull request Sep 6, 2018
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.

An illegal '0' character is appended to a 304 Not Modified Response

4 participants