diff options
| author | Keryn Knight <keryn@kerynknight.com> | 2022-02-23 16:30:19 +0000 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-03-02 20:23:39 +0100 |
| commit | 95b7d01d3856da323a610338aaa6882e82e4cc48 (patch) | |
| tree | 858c7ecddae28fb0a2842003aaeff84606d29bcb /django/http | |
| parent | 4b2f6ace5789768a5734b017b70b3dec31bb000c (diff) | |
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.
Diffstat (limited to 'django/http')
| -rw-r--r-- | django/http/response.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/django/http/response.py b/django/http/response.py index ce49d78d9b..8ae4719575 100644 --- a/django/http/response.py +++ b/django/http/response.py @@ -111,15 +111,15 @@ class HttpResponseBase: ): self.headers = ResponseHeaders(headers) 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( "'headers' must not contain 'Content-Type' when the " "'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 = [] # This parameter is set by the handler. It's necessary to preserve the # historical behavior of request_finished. |
