MCPcopy
hub / github.com/tornadoweb/tornado / set_headers

Method set_headers

tornado/web.py:2888–2912  ·  view source on GitHub ↗

Sets the content and caching headers on the response. .. versionadded:: 3.1

(self)

Source from the content-addressed store, hash-verified

2886 return f'"{version_hash}"'
2887
2888 def set_headers(self) -> None:
2889 """Sets the content and caching headers on the response.
2890
2891 .. versionadded:: 3.1
2892 """
2893 self.set_header("Accept-Ranges", "bytes")
2894 self.set_etag_header()
2895
2896 if self.modified is not None:
2897 self.set_header("Last-Modified", self.modified)
2898
2899 content_type = self.get_content_type()
2900 if content_type:
2901 self.set_header("Content-Type", content_type)
2902
2903 cache_time = self.get_cache_time(self.path, self.modified, content_type)
2904 if cache_time > 0:
2905 self.set_header(
2906 "Expires",
2907 datetime.datetime.now(datetime.timezone.utc)
2908 + datetime.timedelta(seconds=cache_time),
2909 )
2910 self.set_header("Cache-Control", "max-age=" + str(cache_time))
2911
2912 self.set_extra_headers(self.path)
2913
2914 def should_return_304(self) -> bool:
2915 """Returns True if the headers indicate that we should return 304.

Callers 1

getMethod · 0.95

Calls 5

get_content_typeMethod · 0.95
get_cache_timeMethod · 0.95
set_extra_headersMethod · 0.95
set_headerMethod · 0.80
set_etag_headerMethod · 0.80

Tested by

no test coverage detected