Merge pull request #1056 from mig5/error_405_early

Communicate a 405 error properly to the UI
This commit is contained in:
Micah Lee 2019-10-20 12:49:12 -04:00 committed by GitHub
commit e9f91a9bcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
)