From e9075deafafa4d896942f05a88c24dda71af6278 Mon Sep 17 00:00:00 2001 From: Ben Sarsgard Date: Tue, 4 Jul 2023 10:57:42 -0400 Subject: [PATCH 1/3] Fixes an issue with HTTPRequest on web exports * disable gzip compression on web export, as this results in HTTPRequest returning an empty body due to a failure in decompression * also check for "Web" in OS.get_name() ("HTML5" appears to be an old value) --- addons/godot-firebase/auth/auth.gd | 3 ++- addons/godot-firebase/database/database.gd | 2 ++ addons/godot-firebase/dynamiclinks/dynamiclinks.gd | 2 ++ addons/godot-firebase/firestore/firestore.gd | 2 ++ addons/godot-firebase/functions/functions.gd | 2 ++ 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/addons/godot-firebase/auth/auth.gd b/addons/godot-firebase/auth/auth.gd index 35e1b3e..3850c15 100644 --- a/addons/godot-firebase/auth/auth.gd +++ b/addons/godot-firebase/auth/auth.gd @@ -147,7 +147,8 @@ func _ready() -> void: tcp_timer.wait_time = tcp_timeout tcp_timer.timeout.connect(_tcp_stream_timer) - if OS.get_name() == "HTML5": + if OS.get_name() == "HTML5" or OS.get_name() == "Web": + accept_gzip = false # Fixes broken gzip compression in web exports _local_uri += "tmp_js_export.html" diff --git a/addons/godot-firebase/database/database.gd b/addons/godot-firebase/database/database.gd index 4d928cb..ab95761 100644 --- a/addons/godot-firebase/database/database.gd +++ b/addons/godot-firebase/database/database.gd @@ -42,6 +42,8 @@ func _on_FirebaseAuth_logout() -> void: func get_database_reference(path : String, filter : Dictionary = {}) -> FirebaseDatabaseReference: var firebase_reference : FirebaseDatabaseReference = FirebaseDatabaseReference.new() var pusher : HTTPRequest = HTTPRequest.new() + if OS.get_name() == "HTML5" or OS.get_name() == "Web": + pusher.accept_gzip = false # Fixes broken gzip compression in web exports pusher.use_threads = true var listener : Node = Node.new() listener.set_script(load("res://addons/http-sse-client/HTTPSSEClient.gd")) diff --git a/addons/godot-firebase/dynamiclinks/dynamiclinks.gd b/addons/godot-firebase/dynamiclinks/dynamiclinks.gd index c23e86c..62cd518 100644 --- a/addons/godot-firebase/dynamiclinks/dynamiclinks.gd +++ b/addons/godot-firebase/dynamiclinks/dynamiclinks.gd @@ -32,6 +32,8 @@ enum Requests { func _set_config(config_json : Dictionary) -> void: _config = config_json _request_list_node = HTTPRequest.new() + if OS.get_name() == "HTML5" or OS.get_name() == "Web": + _request_list_node .accept_gzip = false # Fixes broken gzip compression in web exports _request_list_node.request_completed.connect(_on_request_completed) add_child(_request_list_node) _check_emulating() diff --git a/addons/godot-firebase/firestore/firestore.gd b/addons/godot-firebase/firestore/firestore.gd index 07bb2a7..8a853cd 100644 --- a/addons/godot-firebase/firestore/firestore.gd +++ b/addons/godot-firebase/firestore/firestore.gd @@ -264,6 +264,8 @@ func _pooled_request(task : FirestoreTask) -> void: if not http_request: http_request = HTTPRequest.new() http_request.timeout = 5 + if OS.get_name() == "HTML5" or OS.get_name() == "Web": + http_request.accept_gzip = false # Fixes broken gzip compression in web exports _http_request_pool.append(http_request) add_child(http_request) http_request.request_completed.connect(_on_pooled_request_completed.bind(http_request)) diff --git a/addons/godot-firebase/functions/functions.gd b/addons/godot-firebase/functions/functions.gd index 76855a6..a73a4ba 100644 --- a/addons/godot-firebase/functions/functions.gd +++ b/addons/godot-firebase/functions/functions.gd @@ -168,6 +168,8 @@ func _pooled_request(task : FunctionTask) -> void: if not http_request: http_request = HTTPRequest.new() + if OS.get_name() == "HTML5" or OS.get_name() == "Web": + http_request.accept_gzip = false # Fixes broken gzip compression in web exports _http_request_pool.append(http_request) add_child(http_request) http_request.request_completed.connect(_on_pooled_request_completed.bind(http_request)) From 57508d4fc528ed1d53a9e5c57042dcdac9b88856 Mon Sep 17 00:00:00 2001 From: Ben Sarsgard Date: Tue, 4 Jul 2023 11:03:16 -0400 Subject: [PATCH 2/3] Fix whitespace --- addons/godot-firebase/dynamiclinks/dynamiclinks.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/godot-firebase/dynamiclinks/dynamiclinks.gd b/addons/godot-firebase/dynamiclinks/dynamiclinks.gd index 62cd518..8575519 100644 --- a/addons/godot-firebase/dynamiclinks/dynamiclinks.gd +++ b/addons/godot-firebase/dynamiclinks/dynamiclinks.gd @@ -33,7 +33,7 @@ func _set_config(config_json : Dictionary) -> void: _config = config_json _request_list_node = HTTPRequest.new() if OS.get_name() == "HTML5" or OS.get_name() == "Web": - _request_list_node .accept_gzip = false # Fixes broken gzip compression in web exports + _request_list_node.accept_gzip = false # Fixes broken gzip compression in web exports _request_list_node.request_completed.connect(_on_request_completed) add_child(_request_list_node) _check_emulating() From 37cd3f842d2fde9aa6066a52b6a3e22ac861c80a Mon Sep 17 00:00:00 2001 From: Ben Sarsgard Date: Tue, 4 Jul 2023 11:26:38 -0400 Subject: [PATCH 3/3] Move logic into static utility class --- addons/godot-firebase/Utilies.gd | 8 ++++++++ addons/godot-firebase/auth/auth.gd | 2 +- addons/godot-firebase/database/database.gd | 3 +-- addons/godot-firebase/dynamiclinks/dynamiclinks.gd | 3 +-- addons/godot-firebase/firestore/firestore.gd | 3 +-- addons/godot-firebase/functions/functions.gd | 3 +-- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/addons/godot-firebase/Utilies.gd b/addons/godot-firebase/Utilies.gd index 6e821bc..3b7143b 100644 --- a/addons/godot-firebase/Utilies.gd +++ b/addons/godot-firebase/Utilies.gd @@ -10,3 +10,11 @@ static func get_json_data(value): return json.data return null + + +# HTTPRequeust seems to have an issue in Web exports where the body returns empty +# This appears to be caused by the gzip compression being unsupported, so we +# disable it when web export is detected. +static func fix_http_request(http_request): + if OS.get_name() == "HTML5" or OS.get_name() == "Web": + http_request.accept_gzip = false \ No newline at end of file diff --git a/addons/godot-firebase/auth/auth.gd b/addons/godot-firebase/auth/auth.gd index 3850c15..2c7081f 100644 --- a/addons/godot-firebase/auth/auth.gd +++ b/addons/godot-firebase/auth/auth.gd @@ -147,8 +147,8 @@ func _ready() -> void: tcp_timer.wait_time = tcp_timeout tcp_timer.timeout.connect(_tcp_stream_timer) + Utilities.fix_http_request(self) if OS.get_name() == "HTML5" or OS.get_name() == "Web": - accept_gzip = false # Fixes broken gzip compression in web exports _local_uri += "tmp_js_export.html" diff --git a/addons/godot-firebase/database/database.gd b/addons/godot-firebase/database/database.gd index ab95761..195b699 100644 --- a/addons/godot-firebase/database/database.gd +++ b/addons/godot-firebase/database/database.gd @@ -42,8 +42,7 @@ func _on_FirebaseAuth_logout() -> void: func get_database_reference(path : String, filter : Dictionary = {}) -> FirebaseDatabaseReference: var firebase_reference : FirebaseDatabaseReference = FirebaseDatabaseReference.new() var pusher : HTTPRequest = HTTPRequest.new() - if OS.get_name() == "HTML5" or OS.get_name() == "Web": - pusher.accept_gzip = false # Fixes broken gzip compression in web exports + Utilities.fix_http_request(pusher) pusher.use_threads = true var listener : Node = Node.new() listener.set_script(load("res://addons/http-sse-client/HTTPSSEClient.gd")) diff --git a/addons/godot-firebase/dynamiclinks/dynamiclinks.gd b/addons/godot-firebase/dynamiclinks/dynamiclinks.gd index 8575519..67a1374 100644 --- a/addons/godot-firebase/dynamiclinks/dynamiclinks.gd +++ b/addons/godot-firebase/dynamiclinks/dynamiclinks.gd @@ -32,8 +32,7 @@ enum Requests { func _set_config(config_json : Dictionary) -> void: _config = config_json _request_list_node = HTTPRequest.new() - if OS.get_name() == "HTML5" or OS.get_name() == "Web": - _request_list_node.accept_gzip = false # Fixes broken gzip compression in web exports + Utilities.fix_http_request(_request_list_node) _request_list_node.request_completed.connect(_on_request_completed) add_child(_request_list_node) _check_emulating() diff --git a/addons/godot-firebase/firestore/firestore.gd b/addons/godot-firebase/firestore/firestore.gd index 8a853cd..317c60e 100644 --- a/addons/godot-firebase/firestore/firestore.gd +++ b/addons/godot-firebase/firestore/firestore.gd @@ -264,8 +264,7 @@ func _pooled_request(task : FirestoreTask) -> void: if not http_request: http_request = HTTPRequest.new() http_request.timeout = 5 - if OS.get_name() == "HTML5" or OS.get_name() == "Web": - http_request.accept_gzip = false # Fixes broken gzip compression in web exports + Utilities.fix_http_request(http_request) _http_request_pool.append(http_request) add_child(http_request) http_request.request_completed.connect(_on_pooled_request_completed.bind(http_request)) diff --git a/addons/godot-firebase/functions/functions.gd b/addons/godot-firebase/functions/functions.gd index a73a4ba..78ccd0c 100644 --- a/addons/godot-firebase/functions/functions.gd +++ b/addons/godot-firebase/functions/functions.gd @@ -168,8 +168,7 @@ func _pooled_request(task : FunctionTask) -> void: if not http_request: http_request = HTTPRequest.new() - if OS.get_name() == "HTML5" or OS.get_name() == "Web": - http_request.accept_gzip = false # Fixes broken gzip compression in web exports + Utilities.fix_http_request(http_request) _http_request_pool.append(http_request) add_child(http_request) http_request.request_completed.connect(_on_pooled_request_completed.bind(http_request))