From 9eebd2e6e8493e0683c899e7d77c5d3e0658f60f Mon Sep 17 00:00:00 2001 From: JustArchi Date: Mon, 4 Jan 2021 15:29:47 +0100 Subject: [PATCH] Always provide content to StreamResponse A failed request that returned object will have empty stream at worst, but never null. That stream is required in userspace for working with. --- ArchiSteamFarm/WebBrowser.cs | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/ArchiSteamFarm/WebBrowser.cs b/ArchiSteamFarm/WebBrowser.cs index 75c7ca7bd..59c0bcdf5 100644 --- a/ArchiSteamFarm/WebBrowser.cs +++ b/ArchiSteamFarm/WebBrowser.cs @@ -380,9 +380,6 @@ namespace ArchiSteamFarm { // We're not handling this error, do not try again break; } - - // We're handling this error, the content isn't available, deal with it - return new StreamResponse(response); } if (response.StatusCode.IsServerErrorCode()) { @@ -390,9 +387,6 @@ namespace ArchiSteamFarm { // We're not handling this error, try again continue; } - - // We're handling this error, the content isn't available, deal with it - return new StreamResponse(response); } return new StreamResponse(response, await response.Content.ReadAsStreamAsync().ConfigureAwait(false)); @@ -429,9 +423,6 @@ namespace ArchiSteamFarm { // We're not handling this error, do not try again break; } - - // We're handling this error, the content isn't available, deal with it - return new StringResponse(response); } if (response.StatusCode.IsServerErrorCode()) { @@ -439,9 +430,6 @@ namespace ArchiSteamFarm { // We're not handling this error, try again continue; } - - // We're handling this error, the content isn't available, deal with it - return new StringResponse(response); } return new StringResponse(response, await response.Content.ReadAsStringAsync().ConfigureAwait(false)); @@ -775,9 +763,6 @@ namespace ArchiSteamFarm { // We're not handling this error, do not try again break; } - - // We're handling this error, the content isn't available, deal with it - return new StreamResponse(response); } if (response.StatusCode.IsServerErrorCode()) { @@ -785,9 +770,6 @@ namespace ArchiSteamFarm { // We're not handling this error, try again continue; } - - // We're handling this error, the content isn't available, deal with it - return new StreamResponse(response); } return new StreamResponse(response, await response.Content.ReadAsStreamAsync().ConfigureAwait(false)); @@ -1121,21 +1103,11 @@ namespace ArchiSteamFarm { private readonly HttpResponseMessage ResponseMessage; - internal StreamResponse(HttpResponseMessage httpResponseMessage, Stream content) : this(httpResponseMessage) { - if (httpResponseMessage == null) { - throw new ArgumentNullException(nameof(httpResponseMessage)); - } - + internal StreamResponse(HttpResponseMessage httpResponseMessage, Stream content) : base(httpResponseMessage) { + ResponseMessage = httpResponseMessage ?? throw new ArgumentNullException(nameof(httpResponseMessage)); Content = content ?? throw new ArgumentNullException(nameof(content)); - } - - internal StreamResponse(HttpResponseMessage httpResponseMessage) : base(httpResponseMessage) { - if (httpResponseMessage == null) { - throw new ArgumentNullException(nameof(httpResponseMessage)); - } Length = httpResponseMessage.Content.Headers.ContentLength.GetValueOrDefault(); - ResponseMessage = httpResponseMessage; } public async ValueTask DisposeAsync() {