Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Symbol Names to match Godot, Fix Request Call Args #186

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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