Skip to content

Commit

Permalink
Read content ASAP and properly use HttpClient and response (#1499)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss authored Oct 15, 2023
1 parent 6894ba0 commit 6de269a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions OpenDreamRuntime/Procs/Native/DreamProcNativeWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,18 @@ public static async Task<DreamValue> NativeProc_Export(AsyncNativeProc.State sta
}
}

// TODO: Maybe cache HttpClient.
var client = new HttpClient();
var response = await client.GetAsync(uri);
// TODO: Definitely cache HttpClient.
using var client = new HttpClient();
using var response = await client.GetAsync(uri);
var contentBytes = await response.Content.ReadAsByteArrayAsync();

var list = state.ObjectTree.CreateList();
foreach (var header in response.Headers) {
// TODO: How to handle headers with multiple values?
list.SetValue(new DreamValue(header.Key), new DreamValue(header.Value.First()));
}

var content = state.ResourceManager.CreateResource(await response.Content.ReadAsByteArrayAsync());
var content = state.ResourceManager.CreateResource(contentBytes);
list.SetValue(new DreamValue("STATUS"), new DreamValue(((int) response.StatusCode).ToString()));
list.SetValue(new DreamValue("CONTENT"), new DreamValue(content));

Expand Down

0 comments on commit 6de269a

Please sign in to comment.