handle HEAD requests correctly

This commit is contained in:
jfriedli 2019-10-02 08:25:55 -07:00
parent d9d4ebf3a2
commit c36fc9c20e
2 changed files with 15 additions and 6 deletions

13
main.py
View file

@ -35,7 +35,7 @@ def create_app(test_config=None):
CORS(app, resources={r"/api/*": {"origins": utils.get_allow_origin_header_value()}})
@app.route('/download/<string:key>/<string:filename>')
def download_file(key:str, filename:str):
def download_file(key: str, filename:str):
if filename != secure_filename(filename):
return redirect(url_for('upload_file'))
@ -173,11 +173,12 @@ def create_app(test_config=None):
class APIDownload(Resource):
def get(self, key: str, filename: str):
complete_path, filepath = is_valid_api_download_file(filename, key)
@after_this_request
def remove_file(response):
os.remove(complete_path)
return response
# Make sure the file is NOT deleted on HEAD requests
if request.method == 'GET':
@after_this_request
def remove_file(response):
os.remove(complete_path)
return response
return send_from_directory(app.config['UPLOAD_FOLDER'], filepath)