implement etag so that it actually works
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
a9834781e9
commit
c97f8df9e9
|
@ -11,9 +11,15 @@ def send_from_cwd(filename):
|
||||||
return send_from_directory(os.getcwd(), 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 = send_file(fp, **kwargs)
|
||||||
response.set_etag(str(crc32(fp.read())))
|
response.set_etag(etag)
|
||||||
fp.seek(0)
|
fp.seek(0)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
@ -72,8 +78,7 @@ def get_volume_info(volume_id):
|
||||||
@app.route('/api/volume/<int:volume_id>/page/<int:page_number>')
|
@app.route('/api/volume/<int:volume_id>/page/<int:page_number>')
|
||||||
def get_volume_page(volume_id, page_number):
|
def get_volume_page(volume_id, page_number):
|
||||||
page = db.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 = send_file_with_etag(page['data'], etag=page['etag'], mimetype=page['mimetype'])
|
||||||
response.set_etag(page['etag'])
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue