From 70c63fe9e8dc22ccf79f646f5a3614532466b6b4 Mon Sep 17 00:00:00 2001 From: Mikael Mengistu Date: Fri, 13 Apr 2018 06:52:27 +0000 Subject: [PATCH] Http.Connections.Client API Review changes (#1987) --- samples/JwtClientSample/Program.cs | 2 +- .../HttpConnection.Log.cs | 1 + .../HttpConnection.cs | 9 +++++++-- .../HttpConnectionOptions.cs | 4 ++-- .../{ => Internal}/Constants.cs | 4 ++-- .../{ => Internal}/DefaultTransportFactory.cs | 4 ++-- .../{ => Internal}/ITransport.cs | 2 +- .../{ => Internal}/ITransportFactory.cs | 2 +- .../Internal/WebSocketsTransport.cs | 4 ++-- .../HubConnectionTests.cs | 2 +- .../HttpConnectionTests.Helpers.cs | 3 ++- .../HttpConnectionTests.Negotiate.cs | 2 +- .../HttpConnectionTests.Transport.cs | 1 + .../TestTransportFactory.cs | 4 ++-- 14 files changed, 26 insertions(+), 18 deletions(-) rename src/Microsoft.AspNetCore.Http.Connections.Client/{ => Internal}/Constants.cs (91%) rename src/Microsoft.AspNetCore.Http.Connections.Client/{ => Internal}/DefaultTransportFactory.cs (95%) rename src/Microsoft.AspNetCore.Http.Connections.Client/{ => Internal}/ITransport.cs (87%) rename src/Microsoft.AspNetCore.Http.Connections.Client/{ => Internal}/ITransportFactory.cs (82%) diff --git a/samples/JwtClientSample/Program.cs b/samples/JwtClientSample/Program.cs index 42fe1623df..5ecfdff7fd 100644 --- a/samples/JwtClientSample/Program.cs +++ b/samples/JwtClientSample/Program.cs @@ -35,7 +35,7 @@ namespace JwtClientSample .WithUrl(ServerUrl + "/broadcast", options => { options.Transports = transportType; - options.AccessTokenFactory = () => _tokens[userId]; + options.AccessTokenProvider = () => _tokens[userId]; }) .Build(); diff --git a/src/Microsoft.AspNetCore.Http.Connections.Client/HttpConnection.Log.cs b/src/Microsoft.AspNetCore.Http.Connections.Client/HttpConnection.Log.cs index b3ef9a74a8..66478d4552 100644 --- a/src/Microsoft.AspNetCore.Http.Connections.Client/HttpConnection.Log.cs +++ b/src/Microsoft.AspNetCore.Http.Connections.Client/HttpConnection.Log.cs @@ -3,6 +3,7 @@ using System; using Microsoft.AspNetCore.Connections; +using Microsoft.AspNetCore.Http.Connections.Client.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Http.Connections.Client diff --git a/src/Microsoft.AspNetCore.Http.Connections.Client/HttpConnection.cs b/src/Microsoft.AspNetCore.Http.Connections.Client/HttpConnection.cs index cc4ad8275e..67ff626653 100644 --- a/src/Microsoft.AspNetCore.Http.Connections.Client/HttpConnection.cs +++ b/src/Microsoft.AspNetCore.Http.Connections.Client/HttpConnection.cs @@ -112,6 +112,11 @@ namespace Microsoft.AspNetCore.Http.Connections.Client _transportFactory = transportFactory; } + public async Task StartAsync() + { + await StartAsync(TransferFormat.Binary); + } + public async Task StartAsync(TransferFormat transferFormat) { await StartAsyncCore(transferFormat).ForceAsync(); @@ -394,9 +399,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Client } // Apply the authorization header in a handler instead of a default header because it can change with each request - if (_httpConnectionOptions.AccessTokenFactory != null) + if (_httpConnectionOptions.AccessTokenProvider != null) { - httpMessageHandler = new AccessTokenHttpMessageHandler(httpMessageHandler, _httpConnectionOptions.AccessTokenFactory); + httpMessageHandler = new AccessTokenHttpMessageHandler(httpMessageHandler, _httpConnectionOptions.AccessTokenProvider); } } diff --git a/src/Microsoft.AspNetCore.Http.Connections.Client/HttpConnectionOptions.cs b/src/Microsoft.AspNetCore.Http.Connections.Client/HttpConnectionOptions.cs index 285cb21dde..965ba8acf4 100644 --- a/src/Microsoft.AspNetCore.Http.Connections.Client/HttpConnectionOptions.cs +++ b/src/Microsoft.AspNetCore.Http.Connections.Client/HttpConnectionOptions.cs @@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Client public Uri Url { get; set; } public HttpTransportType Transports { get; set; } - public Func> AccessTokenFactory { get; set; } + public Func> AccessTokenProvider { get; set; } public TimeSpan CloseTimeout { get; set; } = TimeSpan.FromSeconds(5); public ICredentials Credentials { get; set; } public IWebProxy Proxy { get; set; } @@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Client /// to configure the WebSocket when using the WebSockets transport. /// /// - /// This delegate is invoked after headers from and the access token from + /// This delegate is invoked after headers from and the access token from /// has been applied. /// public Action WebSocketOptions { get; set; } diff --git a/src/Microsoft.AspNetCore.Http.Connections.Client/Constants.cs b/src/Microsoft.AspNetCore.Http.Connections.Client/Internal/Constants.cs similarity index 91% rename from src/Microsoft.AspNetCore.Http.Connections.Client/Constants.cs rename to src/Microsoft.AspNetCore.Http.Connections.Client/Internal/Constants.cs index 3c6b80ffd0..22b41d56f3 100644 --- a/src/Microsoft.AspNetCore.Http.Connections.Client/Constants.cs +++ b/src/Microsoft.AspNetCore.Http.Connections.Client/Internal/Constants.cs @@ -6,9 +6,9 @@ using System.Linq; using System.Net.Http.Headers; using System.Reflection; -namespace Microsoft.AspNetCore.Http.Connections.Client +namespace Microsoft.AspNetCore.Http.Connections.Client.Internal { - public static class Constants + internal static class Constants { public static readonly ProductInfoHeaderValue UserAgentHeader; diff --git a/src/Microsoft.AspNetCore.Http.Connections.Client/DefaultTransportFactory.cs b/src/Microsoft.AspNetCore.Http.Connections.Client/Internal/DefaultTransportFactory.cs similarity index 95% rename from src/Microsoft.AspNetCore.Http.Connections.Client/DefaultTransportFactory.cs rename to src/Microsoft.AspNetCore.Http.Connections.Client/Internal/DefaultTransportFactory.cs index b8f8346da1..e781681b47 100644 --- a/src/Microsoft.AspNetCore.Http.Connections.Client/DefaultTransportFactory.cs +++ b/src/Microsoft.AspNetCore.Http.Connections.Client/Internal/DefaultTransportFactory.cs @@ -8,9 +8,9 @@ using Microsoft.AspNetCore.Http.Connections.Client.Internal; using Microsoft.AspNetCore.Http.Connections.Internal; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Http.Connections.Client +namespace Microsoft.AspNetCore.Http.Connections.Client.Internal { - public class DefaultTransportFactory : ITransportFactory + internal class DefaultTransportFactory : ITransportFactory { private readonly HttpClient _httpClient; private readonly HttpConnectionOptions _httpConnectionOptions; diff --git a/src/Microsoft.AspNetCore.Http.Connections.Client/ITransport.cs b/src/Microsoft.AspNetCore.Http.Connections.Client/Internal/ITransport.cs similarity index 87% rename from src/Microsoft.AspNetCore.Http.Connections.Client/ITransport.cs rename to src/Microsoft.AspNetCore.Http.Connections.Client/Internal/ITransport.cs index db657f88ed..8f133a2d5d 100644 --- a/src/Microsoft.AspNetCore.Http.Connections.Client/ITransport.cs +++ b/src/Microsoft.AspNetCore.Http.Connections.Client/Internal/ITransport.cs @@ -6,7 +6,7 @@ using System.IO.Pipelines; using System.Threading.Tasks; using Microsoft.AspNetCore.Connections; -namespace Microsoft.AspNetCore.Http.Connections.Client +namespace Microsoft.AspNetCore.Http.Connections.Client.Internal { public interface ITransport : IDuplexPipe { diff --git a/src/Microsoft.AspNetCore.Http.Connections.Client/ITransportFactory.cs b/src/Microsoft.AspNetCore.Http.Connections.Client/Internal/ITransportFactory.cs similarity index 82% rename from src/Microsoft.AspNetCore.Http.Connections.Client/ITransportFactory.cs rename to src/Microsoft.AspNetCore.Http.Connections.Client/Internal/ITransportFactory.cs index 8c1557227e..7c763d3ea0 100644 --- a/src/Microsoft.AspNetCore.Http.Connections.Client/ITransportFactory.cs +++ b/src/Microsoft.AspNetCore.Http.Connections.Client/Internal/ITransportFactory.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Http.Connections.Client +namespace Microsoft.AspNetCore.Http.Connections.Client.Internal { public interface ITransportFactory { diff --git a/src/Microsoft.AspNetCore.Http.Connections.Client/Internal/WebSocketsTransport.cs b/src/Microsoft.AspNetCore.Http.Connections.Client/Internal/WebSocketsTransport.cs index b1ce55b776..74d82ef937 100644 --- a/src/Microsoft.AspNetCore.Http.Connections.Client/Internal/WebSocketsTransport.cs +++ b/src/Microsoft.AspNetCore.Http.Connections.Client/Internal/WebSocketsTransport.cs @@ -79,9 +79,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Client.Internal _webSocket.Options.UseDefaultCredentials = httpConnectionOptions.UseDefaultCredentials.Value; } - if (httpConnectionOptions.AccessTokenFactory != null) + if (httpConnectionOptions.AccessTokenProvider != null) { - _accessTokenFactory = httpConnectionOptions.AccessTokenFactory; + _accessTokenFactory = httpConnectionOptions.AccessTokenProvider; } httpConnectionOptions.WebSocketOptions?.Invoke(_webSocket.Options); diff --git a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs index 5090acdf76..8182594fa4 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs @@ -717,7 +717,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests .WithLoggerFactory(loggerFactory) .WithUrl(_serverFixture.Url + "/authorizedhub", transportType, options => { - options.AccessTokenFactory = AccessTokenFactory; + options.AccessTokenProvider = AccessTokenFactory; }) .Build(); try diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.Helpers.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.Helpers.cs index 99f915e0a3..b355058524 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.Helpers.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.Helpers.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Http.Connections; using Microsoft.AspNetCore.Http.Connections.Client; +using Microsoft.AspNetCore.Http.Connections.Client.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; @@ -27,7 +28,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests { Transports = transportType ?? HttpTransportType.LongPolling, HttpMessageHandlerFactory = (httpMessageHandler) => httpHandler ?? TestHttpMessageHandler.CreateDefault(), - AccessTokenFactory = accessTokenFactory, + AccessTokenProvider = accessTokenFactory, }; if (url != null) { diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.Negotiate.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.Negotiate.cs index 31e078782a..03864a4a4c 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.Negotiate.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.Negotiate.cs @@ -7,7 +7,7 @@ using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Http.Connections; -using Microsoft.AspNetCore.Http.Connections.Client; +using Microsoft.AspNetCore.Http.Connections.Client.Internal; using Moq; using Newtonsoft.Json; using Xunit; diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.Transport.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.Transport.cs index f388328bd4..457b5b94d3 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.Transport.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HttpConnectionTests.Transport.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Http.Connections; using Microsoft.AspNetCore.Http.Connections.Client; +using Microsoft.AspNetCore.Http.Connections.Client.Internal; using Xunit; namespace Microsoft.AspNetCore.SignalR.Client.Tests diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestTransportFactory.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestTransportFactory.cs index a601c2ad7f..4f5d7b7ef6 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestTransportFactory.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestTransportFactory.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.Http.Connections; -using Microsoft.AspNetCore.Http.Connections.Client; +using Microsoft.AspNetCore.Http.Connections.Client.Internal; namespace Microsoft.AspNetCore.SignalR.Client.Tests { - public class TestTransportFactory : ITransportFactory + internal class TestTransportFactory : ITransportFactory { private readonly ITransport _transport;