Updated scanner to infer when it has reached the end of results.
This commit is contained in:
@@ -2,10 +2,10 @@
|
||||
|
||||
public class HttpService(HttpClient httpClient) : IHttpService
|
||||
{
|
||||
public Task<string> GetStringAsync(string url, CancellationToken cancellationToken)
|
||||
=> GetStringAsync(url, new Dictionary<string, string>(), cancellationToken);
|
||||
public Task<HttpStringResponse> GetAsync(string url, CancellationToken cancellationToken)
|
||||
=> GetAsync(url, new Dictionary<string, string>(), cancellationToken);
|
||||
|
||||
public async Task<string> GetStringAsync(string url, IDictionary<string, string> headers, CancellationToken cancellationToken)
|
||||
public async Task<HttpStringResponse> GetAsync(string url, IDictionary<string, string> headers, CancellationToken cancellationToken)
|
||||
{
|
||||
using HttpRequestMessage request = new(HttpMethod.Get, url);
|
||||
|
||||
@@ -14,11 +14,18 @@ public class HttpService(HttpClient httpClient) : IHttpService
|
||||
request.Headers.TryAddWithoutValidation(header.Key, header.Value);
|
||||
}
|
||||
|
||||
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("JSMR/1.0");
|
||||
request.Headers.UserAgent.ParseAdd("JSMR/1.0");
|
||||
|
||||
using HttpResponseMessage response = await httpClient.SendAsync(request, cancellationToken);
|
||||
response.EnsureSuccessStatusCode();
|
||||
using HttpResponseMessage response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
|
||||
|
||||
return await response.Content.ReadAsStringAsync(cancellationToken);
|
||||
string? content = response.Content is null
|
||||
? null
|
||||
: await response.Content.ReadAsStringAsync(cancellationToken);
|
||||
|
||||
return new HttpStringResponse
|
||||
{
|
||||
StatusCode = response.StatusCode,
|
||||
Content = content
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user