Refs #33546 -- Optimized handling content types in HttpResponseBase.__init__().

This removes an extraneous conditional causing "Content-Type" to be
checked within the ResponseHeaders twice, if a content_type parameter
is provided.
This commit is contained in:
Keryn Knight 2022-02-23 16:30:19 +00:00 committed by Mariusz Felisiak
parent 4b2f6ace57
commit 95b7d01d38
1 changed files with 5 additions and 5 deletions

View File

@ -111,15 +111,15 @@ class HttpResponseBase:
): ):
self.headers = ResponseHeaders(headers) self.headers = ResponseHeaders(headers)
self._charset = charset self._charset = charset
if content_type and "Content-Type" in self.headers: if "Content-Type" not in self.headers:
if content_type is None:
content_type = f"text/html; charset={self.charset}"
self.headers["Content-Type"] = content_type
elif content_type:
raise ValueError( raise ValueError(
"'headers' must not contain 'Content-Type' when the " "'headers' must not contain 'Content-Type' when the "
"'content_type' parameter is provided." "'content_type' parameter is provided."
) )
if "Content-Type" not in self.headers:
if content_type is None:
content_type = "text/html; charset=%s" % self.charset
self.headers["Content-Type"] = content_type
self._resource_closers = [] self._resource_closers = []
# This parameter is set by the handler. It's necessary to preserve the # This parameter is set by the handler. It's necessary to preserve the
# historical behavior of request_finished. # historical behavior of request_finished.