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 =>
|
.WithUrl(ServerUrl + "/broadcast", options =>
|
||||||
{
|
{
|
||||||
options.Transports = transportType;
|
options.Transports = transportType;
|
||||||
options.AccessTokenFactory = () => _tokens[userId];
|
options.AccessTokenProvider = () => _tokens[userId];
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNetCore.Connections;
|
using Microsoft.AspNetCore.Connections;
|
||||||
|
using Microsoft.AspNetCore.Http.Connections.Client.Internal;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Http.Connections.Client
|
namespace Microsoft.AspNetCore.Http.Connections.Client
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,11 @@ namespace Microsoft.AspNetCore.Http.Connections.Client
|
||||||
_transportFactory = transportFactory;
|
_transportFactory = transportFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task StartAsync()
|
||||||
|
{
|
||||||
|
await StartAsync(TransferFormat.Binary);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task StartAsync(TransferFormat transferFormat)
|
public async Task StartAsync(TransferFormat transferFormat)
|
||||||
{
|
{
|
||||||
await StartAsyncCore(transferFormat).ForceAsync();
|
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
|
// 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 Uri Url { get; set; }
|
||||||
public HttpTransportType Transports { 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 TimeSpan CloseTimeout { get; set; } = TimeSpan.FromSeconds(5);
|
||||||
public ICredentials Credentials { get; set; }
|
public ICredentials Credentials { get; set; }
|
||||||
public IWebProxy Proxy { 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.
|
/// to configure the WebSocket when using the WebSockets transport.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <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.
|
/// has been applied.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public Action<ClientWebSocketOptions> WebSocketOptions { get; set; }
|
public Action<ClientWebSocketOptions> WebSocketOptions { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ using System.Linq;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Reflection;
|
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;
|
public static readonly ProductInfoHeaderValue UserAgentHeader;
|
||||||
|
|
||||||
|
|
@ -8,9 +8,9 @@ using Microsoft.AspNetCore.Http.Connections.Client.Internal;
|
||||||
using Microsoft.AspNetCore.Http.Connections.Internal;
|
using Microsoft.AspNetCore.Http.Connections.Internal;
|
||||||
using Microsoft.Extensions.Logging;
|
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 HttpClient _httpClient;
|
||||||
private readonly HttpConnectionOptions _httpConnectionOptions;
|
private readonly HttpConnectionOptions _httpConnectionOptions;
|
||||||
|
|
@ -6,7 +6,7 @@ using System.IO.Pipelines;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Connections;
|
using Microsoft.AspNetCore.Connections;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Http.Connections.Client
|
namespace Microsoft.AspNetCore.Http.Connections.Client.Internal
|
||||||
{
|
{
|
||||||
public interface ITransport : IDuplexPipe
|
public interface ITransport : IDuplexPipe
|
||||||
{
|
{
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// 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
|
public interface ITransportFactory
|
||||||
{
|
{
|
||||||
|
|
@ -79,9 +79,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Client.Internal
|
||||||
_webSocket.Options.UseDefaultCredentials = httpConnectionOptions.UseDefaultCredentials.Value;
|
_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);
|
httpConnectionOptions.WebSocketOptions?.Invoke(_webSocket.Options);
|
||||||
|
|
|
||||||
|
|
@ -717,7 +717,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
||||||
.WithLoggerFactory(loggerFactory)
|
.WithLoggerFactory(loggerFactory)
|
||||||
.WithUrl(_serverFixture.Url + "/authorizedhub", transportType, options =>
|
.WithUrl(_serverFixture.Url + "/authorizedhub", transportType, options =>
|
||||||
{
|
{
|
||||||
options.AccessTokenFactory = AccessTokenFactory;
|
options.AccessTokenProvider = AccessTokenFactory;
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
try
|
try
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Connections;
|
using Microsoft.AspNetCore.Connections;
|
||||||
using Microsoft.AspNetCore.Http.Connections;
|
using Microsoft.AspNetCore.Http.Connections;
|
||||||
using Microsoft.AspNetCore.Http.Connections.Client;
|
using Microsoft.AspNetCore.Http.Connections.Client;
|
||||||
|
using Microsoft.AspNetCore.Http.Connections.Client.Internal;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
|
||||||
|
|
@ -27,7 +28,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
||||||
{
|
{
|
||||||
Transports = transportType ?? HttpTransportType.LongPolling,
|
Transports = transportType ?? HttpTransportType.LongPolling,
|
||||||
HttpMessageHandlerFactory = (httpMessageHandler) => httpHandler ?? TestHttpMessageHandler.CreateDefault(),
|
HttpMessageHandlerFactory = (httpMessageHandler) => httpHandler ?? TestHttpMessageHandler.CreateDefault(),
|
||||||
AccessTokenFactory = accessTokenFactory,
|
AccessTokenProvider = accessTokenFactory,
|
||||||
};
|
};
|
||||||
if (url != null)
|
if (url != null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Connections;
|
using Microsoft.AspNetCore.Connections;
|
||||||
using Microsoft.AspNetCore.Http.Connections;
|
using Microsoft.AspNetCore.Http.Connections;
|
||||||
using Microsoft.AspNetCore.Http.Connections.Client;
|
using Microsoft.AspNetCore.Http.Connections.Client.Internal;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Connections;
|
using Microsoft.AspNetCore.Connections;
|
||||||
using Microsoft.AspNetCore.Http.Connections;
|
using Microsoft.AspNetCore.Http.Connections;
|
||||||
using Microsoft.AspNetCore.Http.Connections.Client;
|
using Microsoft.AspNetCore.Http.Connections.Client;
|
||||||
|
using Microsoft.AspNetCore.Http.Connections.Client.Internal;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
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.
|
// 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;
|
||||||
using Microsoft.AspNetCore.Http.Connections.Client;
|
using Microsoft.AspNetCore.Http.Connections.Client.Internal;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
||||||
{
|
{
|
||||||
public class TestTransportFactory : ITransportFactory
|
internal class TestTransportFactory : ITransportFactory
|
||||||
{
|
{
|
||||||
private readonly ITransport _transport;
|
private readonly ITransport _transport;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue