summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel Jacq <mig@mig5.net>2021-05-11 08:41:17 +1000
committerMiguel Jacq <mig@mig5.net>2021-05-11 08:41:17 +1000
commit0b6db6559dff6ee314fe7fa9f68d2682d8abda9c (patch)
treec01ee70bb20beba6016c17110a39e402aa7491f8
parenta55a59e021d33ec0063bd41cc01a93abf6066d5a (diff)
downloadonionshare-0b6db6559dff6ee314fe7fa9f68d2682d8abda9c.tar.gz
onionshare-0b6db6559dff6ee314fe7fa9f68d2682d8abda9c.zip
Adds attribute self.mode_supports_file_requests in Web class. Don't send REQUEST_INDIVIDUAL_FILE_STARTED to the frontend if the mode doesn't support this, so that we don't trigger a chain reaction of toggling history widgets and the like. Set this attribute to True by default since most modes use it, but turn it off for Chat mode. Prevents an exception when sending a bad HTTP method or a 404 to a chat room
-rw-r--r--cli/onionshare_cli/web/web.py37
1 files changed, 22 insertions, 15 deletions
diff --git a/cli/onionshare_cli/web/web.py b/cli/onionshare_cli/web/web.py
index 96c6295c..b947b491 100644
--- a/cli/onionshare_cli/web/web.py
+++ b/cli/onionshare_cli/web/web.py
@@ -152,6 +152,7 @@ class Web:
self.receive_mode = None
self.website_mode = None
self.chat_mode = None
+ self.mode_supports_file_requests = True
if self.mode == "share":
self.share_mode = ShareModeWeb(self.common, self)
elif self.mode == "receive":
@@ -162,6 +163,9 @@ class Web:
self.socketio = SocketIO()
self.socketio.init_app(self.app)
self.chat_mode = ChatModeWeb(self.common, self)
+ # Chat mode has no concept of individual file requests that
+ # turn into history widgets in the GUI
+ self.mode_supports_file_requests = False
self.cleanup_filenames = []
@@ -294,11 +298,12 @@ 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},
- )
+ if self.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(
@@ -307,11 +312,12 @@ 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},
- )
+ if self.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(
@@ -320,11 +326,12 @@ class Web:
return self.add_security_headers(r)
def error500(self, history_id):
- self.add_request(
- self.REQUEST_INDIVIDUAL_FILE_STARTED,
- request.path,
- {"id": history_id, "status_code": 500},
- )
+ if self.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(