summaryrefslogtreecommitdiff
path: root/cli/onionshare_cli/web/web.py
diff options
context:
space:
mode:
Diffstat (limited to 'cli/onionshare_cli/web/web.py')
-rw-r--r--cli/onionshare_cli/web/web.py53
1 files changed, 43 insertions, 10 deletions
diff --git a/cli/onionshare_cli/web/web.py b/cli/onionshare_cli/web/web.py
index d88a7e4e..56e307b4 100644
--- a/cli/onionshare_cli/web/web.py
+++ b/cli/onionshare_cli/web/web.py
@@ -229,6 +229,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):
"""
@@ -280,11 +294,13 @@ class Web:
return self.add_security_headers(r)
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)
r = make_response(
@@ -293,11 +309,13 @@ class Web:
return self.add_security_headers(r)
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)
r = make_response(
@@ -305,6 +323,21 @@ class Web:
)
return self.add_security_headers(r)
+ 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)
+ r = make_response(
+ render_template("500.html", static_url_path=self.static_url_path), 500
+ )
+ return self.add_security_headers(r)
+
def add_security_headers(self, r):
"""
Add security headers to a request