internal HttpClient Http;
internal HttpClient HttpUpload;
- internal HttpClient HttpStreaming;
internal ITwitterCredential Credential { get; }
Networking.WebProxyChanged += this.Networking_WebProxyChanged;
}
- [MemberNotNull(nameof(Http), nameof(HttpUpload), nameof(HttpStreaming))]
+ [MemberNotNull(nameof(Http), nameof(HttpUpload))]
private void InitializeHttpClients()
{
this.Http = InitializeHttpClient(this.Credential);
this.HttpUpload = InitializeHttpClient(this.Credential);
this.HttpUpload.Timeout = Networking.UploadImageTimeout;
-
- this.HttpStreaming = InitializeHttpClient(this.Credential, disableGzip: true);
- this.HttpStreaming.Timeout = Timeout.InfiniteTimeSpan;
}
public async Task<ApiResponse> SendAsync(IHttpRequest request)
}
}
- public async Task<Stream> GetStreamingStreamAsync(Uri uri, IDictionary<string, string>? param)
- {
- var requestUri = new Uri(RestApiBase, uri);
-
- if (param != null)
- requestUri = new Uri(requestUri, "?" + MyCommon.BuildQueryString(param));
-
- try
- {
- var request = new HttpRequestMessage(HttpMethod.Get, requestUri);
- var response = await this.HttpStreaming.SendAsync(request, HttpCompletionOption.ResponseHeadersRead)
- .ConfigureAwait(false);
-
- await TwitterApiConnection.CheckStatusCode(response)
- .ConfigureAwait(false);
-
- return await response.Content.ReadAsStreamAsync()
- .ConfigureAwait(false);
- }
- catch (HttpRequestException ex)
- {
- throw TwitterApiException.CreateFromException(ex);
- }
- catch (OperationCanceledException ex)
- {
- throw TwitterApiException.CreateFromException(ex);
- }
- }
-
public async Task<LazyJson<T>> PostLazyAsync<T>(Uri uri, IDictionary<string, string>? param)
{
var requestUri = new Uri(RestApiBase, uri);
Networking.WebProxyChanged -= this.Networking_WebProxyChanged;
this.Http.Dispose();
this.HttpUpload.Dispose();
- this.HttpStreaming.Dispose();
}
}
}
}
- private static HttpClient InitializeHttpClient(ITwitterCredential credential, bool disableGzip = false)
+ private static HttpClient InitializeHttpClient(ITwitterCredential credential)
{
var builder = Networking.CreateHttpClientBuilder();
- builder.SetupHttpClientHandler(x =>
- {
- x.CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache);
-
- if (disableGzip)
- x.AutomaticDecompression = DecompressionMethods.None;
- });
+ builder.SetupHttpClientHandler(
+ x => x.CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache)
+ );
builder.AddHandler(x => credential.CreateHttpHandler(x));