OSDN Git Service

TwitterApiConnection.GetStreamingStreamAsyncメソッドを削除
authorKimura Youichi <kim.upsilon@bucyou.net>
Mon, 11 Dec 2023 16:39:40 +0000 (01:39 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Mon, 11 Dec 2023 17:09:59 +0000 (02:09 +0900)
OpenTween/Connection/IApiConnectionLegacy.cs
OpenTween/Connection/TwitterApiConnection.cs

index 9b9e7d8..839ad46 100644 (file)
@@ -34,8 +34,6 @@ namespace OpenTween.Connection
     {
         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);
index bf81c23..0e86060 100644 (file)
@@ -54,7 +54,6 @@ namespace OpenTween.Connection
 
         internal HttpClient Http;
         internal HttpClient HttpUpload;
-        internal HttpClient HttpStreaming;
 
         internal ITwitterCredential Credential { get; }
 
@@ -71,16 +70,13 @@ namespace OpenTween.Connection
             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)
@@ -164,35 +160,6 @@ namespace OpenTween.Connection
             }
         }
 
-        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);
@@ -438,7 +405,6 @@ namespace OpenTween.Connection
                 Networking.WebProxyChanged -= this.Networking_WebProxyChanged;
                 this.Http.Dispose();
                 this.HttpUpload.Dispose();
-                this.HttpStreaming.Dispose();
             }
         }
 
@@ -524,17 +490,13 @@ namespace OpenTween.Connection
             }
         }
 
-        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));