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

DNM: Benchmark overhead of setdefault calls in _prepare_headers #9898

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions aiohttp/web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,15 @@ async def _prepare_headers(self) -> None:
# https://datatracker.ietf.org/doc/html/rfc9112#section-6.1-13
if hdrs.TRANSFER_ENCODING in headers:
del headers[hdrs.TRANSFER_ENCODING]
elif (writer.length if self._length_check else self.content_length) != 0:
elif (
writer.length if self._length_check else self.content_length
) != 0 and hdrs.CONTENT_TYPE not in headers:
# https://www.rfc-editor.org/rfc/rfc9110#section-8.3-5
headers.setdefault(hdrs.CONTENT_TYPE, "application/octet-stream")
headers.setdefault(hdrs.DATE, rfc822_formatted_time())
headers.setdefault(hdrs.SERVER, SERVER_SOFTWARE)

headers[hdrs.CONTENT_TYPE] = "application/octet-stream"
if hdrs.DATE not in headers:
headers[hdrs.DATE] = rfc822_formatted_time()
if hdrs.SERVER not in headers:
headers[hdrs.SERVER] = SERVER_SOFTWARE
# connection header
if hdrs.CONNECTION not in headers:
if keep_alive:
Expand Down
Loading