Http.Connections.Client API Review changes (#1987)
This commit is contained in:
parent
0ee4a86564
commit
70c63fe9e8
|
|
@ -35,7 +35,7 @@ namespace JwtClientSample
|
|||
.WithUrl(ServerUrl + "/broadcast", options =>
|
||||
{
|
||||
options.Transports = transportType;
|
||||
options.AccessTokenFactory = () => _tokens[userId];
|
||||
options.AccessTokenProvider = () => _tokens[userId];
|
||||
})
|
||||
.Build();
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
@ -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;
|
||||
|
|
@ -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
|
||||
{
|
||||
|
|
@ -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
|
||||
{
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue