Allow HEAD to check if backup exists

This commit is contained in:
dave 2015-12-29 22:34:46 -08:00
parent cb6ab90619
commit 4a86eec4c5
1 changed files with 14 additions and 0 deletions

View File

@ -22,6 +22,15 @@ def get_backup_dir(backup_name):
return backup_path
def handle_head(backup_name):
try:
backup_path = get_backup_dir(backup_name)
start_response(extra_headers=['Content-length: 0'])
except:
start_response(status_code=("404", "Not Found",), extra_headers=['Content-length: 0'])
exit(0)
def handle_get_rsync(backup_name):
"""
Prints the absolute path an rsync backup should pull from
@ -67,6 +76,11 @@ def handle_req():
# Should respond by transferring tar.gz data
handle_get_archive(params["name"])
elif os.environ['REQUEST_METHOD'] == "HEAD":
# Respond with 200 or 404 depending if backup exists
# TODO: deeper inspection so the headers can be flushed out
handle_head(params["name"])
else:
raise Exception("Invalid request. Params: %s" % params)