fixed some browsers not showing the reply, attempted to fix another error

This commit is contained in:
Max Kross 2023-04-24 19:04:29 +02:00
parent 170400cdba
commit 107e6aa68b
3 changed files with 13 additions and 13 deletions

View File

@ -75,7 +75,7 @@ func _ready() -> void:
# Send a chat message to channel <channel_name> # Send a chat message to channel <channel_name>
# chat("TEST", initial_channel) # chat("TEST", initial_channel)
# Send a whisper to target user # Send a whisper to target user (requires user:manage:whispers scope)
# whisper("TEST", initial_channel) # whisper("TEST", initial_channel)
func on_event(type : String, data : Dictionary) -> void: func on_event(type : String, data : Dictionary) -> void:

View File

@ -15,7 +15,6 @@ grow_vertical = 2
[node name="Gift" type="Node" parent="."] [node name="Gift" type="Node" parent="."]
script = ExtResource("1") script = ExtResource("1")
scopes = Array[String](["chat:edit", "chat:read", "moderator:read:followers"])
[node name="ChatContainer" type="VBoxContainer" parent="."] [node name="ChatContainer" type="VBoxContainer" parent="."]
unique_name_in_owner = true unique_name_in_owner = true

View File

@ -205,24 +205,16 @@ func get_token() -> void:
var data : Dictionary = {} var data : Dictionary = {}
for entry in response.split("&"): for entry in response.split("&"):
var pair = entry.split("=") var pair = entry.split("=")
data[pair[0]] = pair[1] data[pair[0]] = pair[1] if pair.size() > 0 else ""
if (data.has("error")): if (data.has("error")):
var msg = "Error %s: %s" % [data["error"], data["error_description"]] var msg = "Error %s: %s" % [data["error"], data["error_description"]]
print(msg) print(msg)
var response_code = 400 send_response(peer, "400 BAD REQUEST", msg.to_utf8_buffer())
var body := msg.to_utf8_buffer()
peer.put_utf8_string("HTTP/1.1 %d\r\n" % response_code)
peer.put_utf8_string("Content-Length: %d\r\n\r\n" % body.size())
peer.put_data(body)
peer.disconnect_from_host() peer.disconnect_from_host()
break break
else: else:
print("Success.") print("Success.")
var response_code = 200 send_response(peer, "200 OK", "Success!".to_utf8_buffer())
var body := "Success!".to_utf8_buffer()
peer.put_utf8_string("HTTP/1.1 %d\r\n" % response_code)
peer.put_utf8_string("Content-Length: %d\r\n\r\n" % body.size())
peer.put_data(body)
peer.disconnect_from_host() peer.disconnect_from_host()
var request : HTTPRequest = HTTPRequest.new() var request : HTTPRequest = HTTPRequest.new()
add_child(request) add_child(request)
@ -238,6 +230,15 @@ func get_token() -> void:
break break
OS.delay_msec(100) OS.delay_msec(100)
func send_response(peer : StreamPeer, response : String, body : PackedByteArray) -> void:
peer.put_data(("HTTP/1.1 %s\r\n" % response).to_utf8_buffer())
peer.put_data("Server: GIFT (Godot Engine)\r\n".to_utf8_buffer())
peer.put_data(("Content-Length: %d\r\n"% body.size()).to_utf8_buffer())
peer.put_data("Connection: close\r\n".to_utf8_buffer())
peer.put_data("Content-Type: text/plain; charset=UTF-8\r\n".to_utf8_buffer())
peer.put_data("\r\n".to_utf8_buffer())
peer.put_data(body)
# If the token is valid, returns the username of the token bearer. # If the token is valid, returns the username of the token bearer.
func is_token_valid(token : String) -> String: func is_token_valid(token : String) -> String:
var request : HTTPRequest = HTTPRequest.new() var request : HTTPRequest = HTTPRequest.new()