Do not retry on empty HTTP content

This is totally valid for handling errors, and 200 OK responses should always carry one (even if empty)
This commit is contained in:
JustArchi
2022-06-19 21:42:22 +02:00
parent 1d520d9071
commit d590a30f20

View File

@@ -133,7 +133,7 @@ public sealed class WebBrowser : IDisposable {
StreamResponse? response = await UrlGetToStream(request, headers, referer, requestOptions | ERequestOptions.ReturnClientErrors, 1, rateLimitingDelay).ConfigureAwait(false);
if (response?.Content == null) {
if (response == null) {
// Request timed out, try again
continue;
}
@@ -163,6 +163,10 @@ public sealed class WebBrowser : IDisposable {
continue;
}
if (response.Content == null) {
throw new InvalidOperationException(nameof(response.Content));
}
if (response.Length > Array.MaxLength) {
throw new InvalidOperationException(nameof(response.Length));
}
@@ -245,7 +249,7 @@ public sealed class WebBrowser : IDisposable {
StreamResponse? response = await UrlGetToStream(request, headers, referer, requestOptions | ERequestOptions.ReturnClientErrors, 1, rateLimitingDelay).ConfigureAwait(false);
if (response?.Content == null) {
if (response == null) {
// Request timed out, try again
continue;
}
@@ -275,6 +279,10 @@ public sealed class WebBrowser : IDisposable {
continue;
}
if (response.Content == null) {
throw new InvalidOperationException(nameof(response.Content));
}
try {
return await HtmlDocumentResponse.Create(response).ConfigureAwait(false);
} catch (Exception e) {
@@ -313,7 +321,7 @@ public sealed class WebBrowser : IDisposable {
StreamResponse? response = await UrlGetToStream(request, headers, referer, requestOptions | ERequestOptions.ReturnClientErrors, 1, rateLimitingDelay).ConfigureAwait(false);
if (response?.Content == null) {
if (response == null) {
// Request timed out, try again
continue;
}
@@ -343,6 +351,10 @@ public sealed class WebBrowser : IDisposable {
continue;
}
if (response.Content == null) {
throw new InvalidOperationException(nameof(response.Content));
}
T? obj;
try {
@@ -571,7 +583,7 @@ public sealed class WebBrowser : IDisposable {
StreamResponse? response = await UrlPostToStream(request, headers, data, referer, requestOptions | ERequestOptions.ReturnClientErrors, 1, rateLimitingDelay).ConfigureAwait(false);
if (response?.Content == null) {
if (response == null) {
// Request timed out, try again
continue;
}
@@ -601,6 +613,10 @@ public sealed class WebBrowser : IDisposable {
continue;
}
if (response.Content == null) {
throw new InvalidOperationException(nameof(response.Content));
}
try {
return await HtmlDocumentResponse.Create(response).ConfigureAwait(false);
} catch (Exception e) {
@@ -639,7 +655,7 @@ public sealed class WebBrowser : IDisposable {
StreamResponse? response = await UrlPostToStream(request, headers, data, referer, requestOptions | ERequestOptions.ReturnClientErrors, 1, rateLimitingDelay).ConfigureAwait(false);
if (response?.Content == null) {
if (response == null) {
// Request timed out, try again
continue;
}
@@ -669,6 +685,10 @@ public sealed class WebBrowser : IDisposable {
continue;
}
if (response.Content == null) {
throw new InvalidOperationException(nameof(response.Content));
}
TResult? obj;
try {