summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorwhew <73732390+whew@users.noreply.github.com>2021-05-31 12:04:24 +0000
committerGitHub <noreply@github.com>2021-05-31 12:04:24 +0000
commitb8b7885a5225decf5ed3273a85df053df8cf4506 (patch)
tree687a8ec8cfa282fd7c854bf5d6dc6bde7f01b478 /cli
parentea72440543a6c5fbb308be21defd0b5dc5f43f81 (diff)
downloadonionshare-b8b7885a5225decf5ed3273a85df053df8cf4506.tar.gz
onionshare-b8b7885a5225decf5ed3273a85df053df8cf4506.zip
resolve conflict in web.py
Diffstat (limited to 'cli')
-rw-r--r--cli/onionshare_cli/web/web.py52
1 files changed, 41 insertions, 11 deletions
diff --git a/cli/onionshare_cli/web/web.py b/cli/onionshare_cli/web/web.py
index 48f40730..7b02173b 100644
--- a/cli/onionshare_cli/web/web.py
+++ b/cli/onionshare_cli/web/web.py
@@ -223,7 +223,7 @@ class Web:
return _check_login()
@self.app.after_request
- def add_security_headers(r):
+ def add_security_headers(self, r):
"""
Add security headers to a response
"""
@@ -244,6 +244,20 @@ class Web:
mode.cur_history_id += 1
return self.error404(history_id)
+ @self.app.errorhandler(405)
+ def method_not_allowed(e):
+ mode = self.get_mode()
+ history_id = mode.cur_history_id
+ mode.cur_history_id += 1
+ return self.error405(history_id)
+
+ @self.app.errorhandler(500)
+ def method_not_allowed(e):
+ mode = self.get_mode()
+ history_id = mode.cur_history_id
+ mode.cur_history_id += 1
+ return self.error500(history_id)
+
@self.app.route("/<password_candidate>/shutdown")
def shutdown(password_candidate):
"""
@@ -289,25 +303,41 @@ class Web:
return render_template("403.html", static_url_path=self.static_url_path), 403
def error404(self, history_id):
- self.add_request(
- self.REQUEST_INDIVIDUAL_FILE_STARTED,
- request.path,
- {"id": history_id, "status_code": 404},
- )
+ mode = self.get_mode()
+ if mode.supports_file_requests:
+ self.add_request(
+ self.REQUEST_INDIVIDUAL_FILE_STARTED,
+ request.path,
+ {"id": history_id, "status_code": 404},
+ )
self.add_request(Web.REQUEST_OTHER, request.path)
return render_template("404.html", static_url_path=self.static_url_path), 404
def error405(self, history_id):
- self.add_request(
- self.REQUEST_INDIVIDUAL_FILE_STARTED,
- request.path,
- {"id": history_id, "status_code": 405},
- )
+ mode = self.get_mode()
+ if mode.supports_file_requests:
+ self.add_request(
+ self.REQUEST_INDIVIDUAL_FILE_STARTED,
+ request.path,
+ {"id": history_id, "status_code": 405},
+ )
self.add_request(Web.REQUEST_OTHER, request.path)
return render_template("405.html", static_url_path=self.static_url_path), 405
+ def error500(self, history_id):
+ mode = self.get_mode()
+ if mode.supports_file_requests:
+ self.add_request(
+ self.REQUEST_INDIVIDUAL_FILE_STARTED,
+ request.path,
+ {"id": history_id, "status_code": 500},
+ )
+
+ self.add_request(Web.REQUEST_OTHER, request.path)
+ return render_template("500.html", static_url_path=self.static_url_path), 500
+
def _safe_select_jinja_autoescape(self, filename):
if filename is None:
return True