From 6de269ae8af556eaa6bf4eebc8fd929f608c593f Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Sun, 15 Oct 2023 14:52:35 -0400 Subject: [PATCH] Read content ASAP and properly use HttpClient and response (#1499) --- OpenDreamRuntime/Procs/Native/DreamProcNativeWorld.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/OpenDreamRuntime/Procs/Native/DreamProcNativeWorld.cs b/OpenDreamRuntime/Procs/Native/DreamProcNativeWorld.cs index c08d5fb8fd..860667aec7 100644 --- a/OpenDreamRuntime/Procs/Native/DreamProcNativeWorld.cs +++ b/OpenDreamRuntime/Procs/Native/DreamProcNativeWorld.cs @@ -51,9 +51,10 @@ public static async Task 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) { @@ -61,7 +62,7 @@ public static async Task NativeProc_Export(AsyncNativeProc.State sta 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));