From c97f8df9e9fe6ab075b6ba715f110c891ed1f741 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sat, 13 Jul 2019 13:55:41 +0000 Subject: [PATCH] implement etag so that it actually works --- mangareader.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mangareader.py b/mangareader.py index a40116b..166982a 100755 --- a/mangareader.py +++ b/mangareader.py @@ -11,9 +11,15 @@ def send_from_cwd(filename): return send_from_directory(os.getcwd(), filename) -def send_file_with_etag(fp, **kwargs): +def send_file_with_etag(fp, etag=None, **kwargs): + if etag is None: + etag = str(crc32(fp.read())) + + if request.if_none_match and etag in request.if_none_match: + return '', 304 + response = send_file(fp, **kwargs) - response.set_etag(str(crc32(fp.read()))) + response.set_etag(etag) fp.seek(0) return response @@ -72,8 +78,7 @@ def get_volume_info(volume_id): @app.route('/api/volume//page/') def get_volume_page(volume_id, page_number): page = db.get_volume_page(volume_id, page_number) - response = send_file(page['data'], mimetype=page['mimetype']) - response.set_etag(page['etag']) + response = send_file_with_etag(page['data'], etag=page['etag'], mimetype=page['mimetype']) return response