From 13826ca5cb0a6951959e9c1a01580876a06be853 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 4 Dec 2019 12:47:16 +0000 Subject: [PATCH] Check etag --- daemon.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/daemon.py b/daemon.py index d9b40fea..858371ce 100644 --- a/daemon.py +++ b/daemon.py @@ -1411,6 +1411,29 @@ class PubServer(BaseHTTPRequestHandler): mediaFileType='audio/mpeg' elif mediaFilename.endswith('.ogg'): mediaFileType='audio/ogg' + + # does an etag header exist? + etagHeader='If-None-Match' + if not self.headers.get(etagHeader): + etagHeader='if-none-match' + if not self.headers.get(etagHeader): + etagHeader='If-none-match' + + if self.headers.get(etagHeader): + oldEtag=self.headers['If-None-Match'] + if os.path.isfile(mediaFilename+'.etag'): + # load the etag from file + currEtag='' + try: + with open(mediaFilename, 'r') as etagFile: + currEtag = etagFile.read() + except: + pass + if oldEtag==currEtag: + # if the etags are the same then only return the header + # not the media + self._set_headers(mediaFileType,mediaBinary,cookie) + return with open(mediaFilename, 'rb') as avFile: mediaBinary = avFile.read() self._set_headers_etag(mediaFilename,mediaFileType,mediaBinary,cookie)