Skip to content

Commit

Permalink
Update Symbol Names to match Godot, Fix Request Call Args (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
beelol authored Mar 13, 2024
1 parent 8ed41d5 commit e76e4dc
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions addons/com.heroiclabs.nakama/dotnet-utils/GodotHttpAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
namespace Nakama {

/// <summary>
/// An HTTP adapter which uses Godot's HTTPRequest node.
/// An Http adapter which uses Godot's HttpRequest node.
/// </summary>
/// <remarks>
/// Note Content-Type header is always set as 'application/json'.
Expand All @@ -39,25 +39,25 @@ public partial class GodotHttpAdapter : Node, IHttpAdapter {
public async Task<string> SendAsync(string method, Uri uri, IDictionary<string, string> headers,
byte[] body, int timeout, CancellationToken? cancellationToken)
{
var req = new HTTPRequest();
var req = new HttpRequest();
req.Timeout = timeout;

if (OS.GetName() != "HTML5") {
req.UseThreads = true;
}

var godot_method = HTTPClient.Method.Get;
var godot_method = HttpClient.Method.Get;
if (method == "POST") {
godot_method = HTTPClient.Method.Post;
godot_method = HttpClient.Method.Post;
}
else if (method == "PUT") {
godot_method = HTTPClient.Method.Put;
godot_method = HttpClient.Method.Put;
}
else if (method == "DELETE") {
godot_method = HTTPClient.Method.Delete;
godot_method = HttpClient.Method.Delete;
}
else if (method == "HEAD") {
godot_method = HTTPClient.Method.Head;
godot_method = HttpClient.Method.Head;
}

var headers_array = new String[headers.Count + 1];
Expand All @@ -71,21 +71,21 @@ public async Task<string> SendAsync(string method, Uri uri, IDictionary<string,
string body_string = body != null ? System.Text.Encoding.UTF8.GetString(body) : "";

AddChild(req);
req.Request(uri.ToString(), headers_array, true, godot_method, body_string);
req.Request(uri.ToString(), headers_array, godot_method, body_string);

Logger?.InfoFormat("Send: method='{0}', uri='{1}', body='{2}'", method, uri, body_string);

Variant[] resultObjects = await ToSignal(req, "request_completed");

HTTPRequest.Result result = (HTTPRequest.Result)(long)resultObjects[0];
HttpRequest.Result result = (HttpRequest.Result)(long)resultObjects[0];
long response_code = (long)resultObjects[1];
string response_body = System.Text.Encoding.UTF8.GetString((byte[])resultObjects[3]);

req.QueueFree();

Logger?.InfoFormat("Received: status={0}, contents='{1}'", response_code, response_body);

if (result == HTTPRequest.Result.Success && response_code >= 200 && response_code <= 299) {
if (result == HttpRequest.Result.Success && response_code >= 200 && response_code <= 299) {
return response_body;
}

Expand Down

0 comments on commit e76e4dc

Please sign in to comment.