Communicate a 405 error properly to the UI

This commit is contained in:
Miguel Jacq 2019-10-19 14:50:40 +11:00
parent c1a147e8e6
commit 6616eba3b2
No known key found for this signature in database
GPG Key ID: EEA4341C6D97A0B6
2 changed files with 13 additions and 4 deletions

View File

@ -162,15 +162,17 @@ class SendBaseModeWeb:
# Tell GUI the individual file started
history_id = self.cur_history_id
self.cur_history_id += 1
# Only GET requests are allowed, any other method should fail
if request.method != "GET":
return self.web.error405(history_id)
self.web.add_request(
self.web.REQUEST_INDIVIDUAL_FILE_STARTED,
path,
{"id": history_id, "filesize": filesize},
)
# Only GET requests are allowed, any other method should fail
if request.method != "GET":
return self.web.error405()
def generate():
chunk_size = 102400 # 100kb

View File

@ -266,7 +266,14 @@ class Web:
)
return self.add_security_headers(r)
def error405(self):
def error405(self, history_id):
self.add_request(
self.REQUEST_INDIVIDUAL_FILE_STARTED,
"{}".format(request.path),
{"id": history_id, "status_code": 405},
)
self.add_request(Web.REQUEST_OTHER, request.path)
r = make_response(
render_template("405.html", static_url_path=self.static_url_path), 405
)