Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_last_modified_not_set_when_mtime_is_zero():
class FakeStatEntry(object):
st_mtime = 0
st_size = 1024
st_mode = stat.S_IFREG
stat_cache = {__file__: FakeStatEntry()}
responder = StaticFile(__file__, [], stat_cache=stat_cache)
response = responder.get_response("GET", {})
response.file.close()
headers_dict = Headers(response.headers)
assert "Last-Modified" not in headers_dict
assert "ETag" not in headers_dict
def get_static_file(self, path, url, stat_cache=None):
# Optimization: bail early if file does not exist
if stat_cache is None and not os.path.exists(path):
raise MissingFileError(path)
headers = Headers([])
self.add_mime_headers(headers, path, url)
self.add_cache_headers(headers, path, url)
if self.allow_all_origins:
headers["Access-Control-Allow-Origin"] = "*"
if self.add_headers_function:
self.add_headers_function(headers, path, url)
return StaticFile(
path,
headers.items(),
stat_cache=stat_cache,
encodings={"gzip": path + ".gz", "br": path + ".br"},
)