From b8b7885a5225decf5ed3273a85df053df8cf4506 Mon Sep 17 00:00:00 2001 From: whew <73732390+whew@users.noreply.github.com> Date: Mon, 31 May 2021 12:04:24 +0000 Subject: [PATCH] resolve conflict in web.py --- cli/onionshare_cli/web/web.py | 52 +++++++++++++++++++++++++++-------- 1 file 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("//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