From 5dd2910e1177bac7477bf38b4c3e70168992da23 Mon Sep 17 00:00:00 2001 From: Bob Mottram <bob@libreserver.org> Date: Sun, 22 May 2022 21:08:56 +0100 Subject: [PATCH] Include last modified time in HEAD --- daemon.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/daemon.py b/daemon.py index 439a9ae87..ca2254298 100644 --- a/daemon.py +++ b/daemon.py @@ -871,11 +871,15 @@ class PubServer(BaseHTTPRequestHandler): self.end_headers() def _set_headers_head(self, file_format: str, length: int, etag: str, - calling_domain: str, permissive: bool) -> None: + calling_domain: str, permissive: bool, + last_modified_time_str: str) -> None: self._set_headers_base(file_format, length, None, calling_domain, permissive) if etag: self.send_header('ETag', '"' + etag + '"') + if last_modified_time_str: + self.send_header('last-modified', + last_modified_time_str) self.end_headers() def _set_headers_etag(self, media_filename: str, file_format: str, @@ -18597,6 +18601,7 @@ class PubServer(BaseHTTPRequestHandler): check_path = self.path etag = None file_length = -1 + last_modified_time_str = None if '/media/' in self.path or \ '/accounts/avatars/' in self.path or \ @@ -18642,6 +18647,12 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(media_filename): check_path = media_filename file_length = os.path.getsize(media_filename) + media_tm = os.path.getmtime(media_filename) + last_modified_time = \ + datetime.datetime.fromtimestamp(media_tm) + time_format_str = '%a, %d %b %Y %H:%M:%S GMT' + last_modified_time_str = \ + last_modified_time.strftime(time_format_str) media_tag_filename = media_filename + '.etag' if os.path.isfile(media_tag_filename): try: @@ -18672,7 +18683,8 @@ class PubServer(BaseHTTPRequestHandler): media_file_type = media_file_mime_type(check_path) self._set_headers_head(media_file_type, file_length, - etag, calling_domain, False) + etag, calling_domain, False, + last_modified_time_str) def _receive_new_post_process(self, post_type: str, path: str, headers: {}, length: int, post_bytes, boundary: str,