Skip to content

Commit

Permalink
Move logic into static utility class
Browse files Browse the repository at this point in the history
  • Loading branch information
bsarsgard committed Jul 4, 2023
1 parent 57508d4 commit 37cd3f8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
8 changes: 8 additions & 0 deletions addons/godot-firebase/Utilies.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion addons/godot-firebase/auth/auth.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
3 changes: 1 addition & 2 deletions addons/godot-firebase/database/database.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
3 changes: 1 addition & 2 deletions addons/godot-firebase/dynamiclinks/dynamiclinks.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions addons/godot-firebase/firestore/firestore.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 1 addition & 2 deletions addons/godot-firebase/functions/functions.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 37cd3f8

Please sign in to comment.