parent
07609a10e6
commit
1272d04ea4
|
|
@ -14,6 +14,7 @@ using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Hosting.Server;
|
using Microsoft.AspNetCore.Hosting.Server;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.TestHost
|
namespace Microsoft.AspNetCore.TestHost
|
||||||
{
|
{
|
||||||
|
|
@ -111,7 +112,15 @@ namespace Microsoft.AspNetCore.TestHost
|
||||||
|
|
||||||
foreach (var header in request.Headers)
|
foreach (var header in request.Headers)
|
||||||
{
|
{
|
||||||
req.Headers.Append(header.Key, header.Value.ToArray());
|
// User-Agent is a space delineated single line header but HttpRequestHeaders parses it as multiple elements.
|
||||||
|
if (string.Equals(header.Key, HeaderNames.UserAgent, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
req.Headers.Append(header.Key, string.Join(" ", header.Value));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
req.Headers.Append(header.Key, header.Value.ToArray());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!req.Host.HasValue)
|
if (!req.Host.HasValue)
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Net.Http.Headers;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.TestHost
|
namespace Microsoft.AspNetCore.TestHost
|
||||||
|
|
@ -85,6 +86,23 @@ namespace Microsoft.AspNetCore.TestHost
|
||||||
return httpClient.GetAsync("https://example.com/");
|
return httpClient.GetAsync("https://example.com/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public Task UserAgentHeaderWorks()
|
||||||
|
{
|
||||||
|
var userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0";
|
||||||
|
var handler = new ClientHandler(new PathString(""), new DummyApplication(context =>
|
||||||
|
{
|
||||||
|
var actualResult = context.Request.Headers[HeaderNames.UserAgent];
|
||||||
|
Assert.Equal(userAgent, actualResult);
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}));
|
||||||
|
var httpClient = new HttpClient(handler);
|
||||||
|
httpClient.DefaultRequestHeaders.Add(HeaderNames.UserAgent, userAgent);
|
||||||
|
|
||||||
|
return httpClient.GetAsync("http://example.com");
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ServerTrailersSetOnResponseAfterContentRead()
|
public async Task ServerTrailersSetOnResponseAfterContentRead()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Net.Http.Headers;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.TestHost
|
namespace Microsoft.AspNetCore.TestHost
|
||||||
|
|
@ -47,6 +48,22 @@ namespace Microsoft.AspNetCore.TestHost
|
||||||
Assert.Null(context.Features.Get<IHttpResponseFeature>().ReasonPhrase);
|
Assert.Null(context.Features.Get<IHttpResponseFeature>().ReasonPhrase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task UserAgentHeaderWorks()
|
||||||
|
{
|
||||||
|
var userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0";
|
||||||
|
var builder = new WebHostBuilder().Configure(app => { });
|
||||||
|
var server = new TestServer(builder);
|
||||||
|
server.BaseAddress = new Uri("https://example.com/");
|
||||||
|
var context = await server.SendAsync(c =>
|
||||||
|
{
|
||||||
|
c.Request.Headers[HeaderNames.UserAgent] = userAgent;
|
||||||
|
});
|
||||||
|
|
||||||
|
var actualResult = context.Request.Headers[HeaderNames.UserAgent];
|
||||||
|
Assert.Equal(userAgent, actualResult);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task SingleSlashNotMovedToPathBase()
|
public async Task SingleSlashNotMovedToPathBase()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue