MCPcopy
hub / github.com/django/django / process_response

Method process_response

django/middleware/http.py:14–36  ·  view source on GitHub ↗
(self, request, response)

Source from the content-addressed store, hash-verified

12 """
13
14 def process_response(self, request, response):
15 # It's too late to prevent an unsafe request with a 412 response, and
16 # for a HEAD request, the response body is always empty so computing
17 # an accurate ETag isn't possible.
18 if request.method != "GET":
19 return response
20
21 if self.needs_etag(response) and not response.has_header("ETag"):
22 set_response_etag(response)
23
24 etag = response.get("ETag")
25 last_modified = response.get("Last-Modified")
26 last_modified = last_modified and parse_http_date_safe(last_modified)
27
28 if etag or last_modified:
29 return get_conditional_response(
30 request,
31 etag=etag,
32 last_modified=last_modified,
33 response=response,
34 )
35
36 return response
37
38 def needs_etag(self, response):
39 """Return True if an ETag header should be added to response."""

Callers

nothing calls this directly

Calls 6

needs_etagMethod · 0.95
set_response_etagFunction · 0.90
parse_http_date_safeFunction · 0.90
get_conditional_responseFunction · 0.90
has_headerMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected