implement etag so that it actually works
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Simon Bruder 2019-07-13 13:55:41 +00:00
parent a9834781e9
commit c97f8df9e9
No known key found for this signature in database
GPG key ID: 6F03E0000CC5B62F

View file

@ -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/<int:volume_id>/page/<int:page_number>')
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