Skip to content

Commit

Permalink
TwitterApiConnection.GetStreamingStreamAsyncメソッドを削除
Browse files Browse the repository at this point in the history
  • Loading branch information
upsilon committed Dec 11, 2023
1 parent 1668176 commit a5614fe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 45 deletions.
2 changes: 0 additions & 2 deletions OpenTween/Connection/IApiConnectionLegacy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public interface IApiConnectionLegacy : IApiConnection, IDisposable
{
Task<T> GetAsync<T>(Uri uri, IDictionary<string, string>? param, string? endpointName);

Task<Stream> GetStreamingStreamAsync(Uri uri, IDictionary<string, string>? param);

Task<LazyJson<T>> PostLazyAsync<T>(Uri uri, IDictionary<string, string>? param);

Task<LazyJson<T>> PostLazyAsync<T>(Uri uri, IDictionary<string, string>? param, IDictionary<string, IMediaItem>? media);
Expand Down
48 changes: 5 additions & 43 deletions OpenTween/Connection/TwitterApiConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public static string RestApiHost

internal HttpClient Http;
internal HttpClient HttpUpload;
internal HttpClient HttpStreaming;

internal ITwitterCredential Credential { get; }

Expand All @@ -71,16 +70,13 @@ public TwitterApiConnection(ITwitterCredential credential)
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)
Expand Down Expand Up @@ -164,35 +160,6 @@ private void ThrowIfRateLimitExceeded(string endpointName)
}
}

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);
Expand Down Expand Up @@ -438,7 +405,6 @@ protected virtual void Dispose(bool disposing)
Networking.WebProxyChanged -= this.Networking_WebProxyChanged;
this.Http.Dispose();
this.HttpUpload.Dispose();
this.HttpStreaming.Dispose();
}
}

Expand Down Expand Up @@ -524,17 +490,13 @@ await TwitterApiConnection.CheckStatusCode(response)
}
}

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));

Expand Down

0 comments on commit a5614fe

Please sign in to comment.