Http.Connections.Client API Review changes (#1987)

This commit is contained in:
Mikael Mengistu 2018-04-13 06:52:27 +00:00 committed by GitHub
parent 0ee4a86564
commit 70c63fe9e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 26 additions and 18 deletions

View File

@ -35,7 +35,7 @@ namespace JwtClientSample
.WithUrl(ServerUrl + "/broadcast", options =>
{
options.Transports = transportType;
options.AccessTokenFactory = () => _tokens[userId];
options.AccessTokenProvider = () => _tokens[userId];
})
.Build();

View File

@ -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

View File

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

View File

@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Client
public Uri Url { get; set; }
public HttpTransportType Transports { get; set; }
public Func<Task<string>> AccessTokenFactory { get; set; }
public Func<Task<string>> 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.
/// </summary>
/// <remarks>
/// This delegate is invoked after headers from <see cref="Headers"/> and the access token from <see cref="AccessTokenFactory"/>
/// This delegate is invoked after headers from <see cref="Headers"/> and the access token from <see cref="AccessTokenProvider"/>
/// has been applied.
/// </remarks>
public Action<ClientWebSocketOptions> WebSocketOptions { get; set; }

View File

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

View File

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

View File

@ -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
{

View File

@ -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
{

View File

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

View File

@ -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

View File

@ -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)
{

View File

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

View File

@ -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

View File

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