Enable tests on CoreCLR (#143).
This commit is contained in:
parent
fdf0b84136
commit
905b5bcfc2
|
|
@ -21,6 +21,7 @@ using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Http.Features.Authentication;
|
using Microsoft.AspNet.Http.Features.Authentication;
|
||||||
|
using Microsoft.AspNet.Testing.xunit;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using AuthenticationSchemes = Microsoft.Net.Http.Server.AuthenticationSchemes;
|
using AuthenticationSchemes = Microsoft.Net.Http.Server.AuthenticationSchemes;
|
||||||
|
|
||||||
|
|
@ -52,11 +53,12 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[ConditionalTheory]
|
||||||
[InlineData(AuthenticationSchemes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationSchemes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented
|
// [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented
|
||||||
[InlineData(AuthenticationSchemes.Basic)]
|
[InlineData(AuthenticationSchemes.Basic)]
|
||||||
|
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "HttpClientHandler issue (https://github.com/dotnet/corefx/issues/5045).")]
|
||||||
public async Task AuthType_RequireAuth_ChallengesAdded(AuthenticationSchemes authType)
|
public async Task AuthType_RequireAuth_ChallengesAdded(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
|
|
@ -71,11 +73,12 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[ConditionalTheory]
|
||||||
[InlineData(AuthenticationSchemes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationSchemes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented
|
// [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented
|
||||||
[InlineData(AuthenticationSchemes.Basic)]
|
[InlineData(AuthenticationSchemes.Basic)]
|
||||||
|
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "HttpClientHandler issue (https://github.com/dotnet/corefx/issues/5045).")]
|
||||||
public async Task AuthType_AllowAnonymousButSpecify401_ChallengesAdded(AuthenticationSchemes authType)
|
public async Task AuthType_AllowAnonymousButSpecify401_ChallengesAdded(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
|
|
@ -94,7 +97,8 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[ConditionalFact]
|
||||||
|
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "HttpClientHandler issue (https://github.com/dotnet/corefx/issues/5045).")]
|
||||||
public async Task MultipleAuthTypes_AllowAnonymousButSpecify401_ChallengesAdded()
|
public async Task MultipleAuthTypes_AllowAnonymousButSpecify401_ChallengesAdded()
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
|
|
@ -293,12 +297,13 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[ConditionalTheory]
|
||||||
[InlineData(AuthenticationSchemes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationSchemes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationSchemes.Digest)]
|
// [InlineData(AuthenticationSchemes.Digest)]
|
||||||
[InlineData(AuthenticationSchemes.Basic)]
|
[InlineData(AuthenticationSchemes.Basic)]
|
||||||
[InlineData(AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)]
|
[InlineData(AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)]
|
||||||
|
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "HttpClientHandler issue (https://github.com/dotnet/corefx/issues/5045).")]
|
||||||
public async Task AuthTypes_ChallengeWithoutAuthTypes_AllChallengesSent(AuthenticationSchemes authType)
|
public async Task AuthTypes_ChallengeWithoutAuthTypes_AllChallengesSent(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
|
|
@ -317,12 +322,13 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[ConditionalTheory]
|
||||||
[InlineData(AuthenticationSchemes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationSchemes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationSchemes.Digest)]
|
// [InlineData(AuthenticationSchemes.Digest)]
|
||||||
[InlineData(AuthenticationSchemes.Basic)]
|
[InlineData(AuthenticationSchemes.Basic)]
|
||||||
[InlineData(AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)]
|
[InlineData(AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)]
|
||||||
|
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "HttpClientHandler issue (https://github.com/dotnet/corefx/issues/5045).")]
|
||||||
public async Task AuthTypes_ChallengeWithAllAuthTypes_AllChallengesSent(AuthenticationSchemes authType)
|
public async Task AuthTypes_ChallengeWithAllAuthTypes_AllChallengesSent(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
|
|
@ -344,11 +350,12 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[ConditionalTheory]
|
||||||
[InlineData(AuthenticationSchemes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationSchemes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationSchemes.Digest)]
|
// [InlineData(AuthenticationSchemes.Digest)]
|
||||||
[InlineData(AuthenticationSchemes.Basic)]
|
[InlineData(AuthenticationSchemes.Basic)]
|
||||||
|
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "HttpClientHandler issue (https://github.com/dotnet/corefx/issues/5045).")]
|
||||||
public async Task AuthTypes_ChallengeOneAuthType_OneChallengeSent(AuthenticationSchemes authType)
|
public async Task AuthTypes_ChallengeOneAuthType_OneChallengeSent(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,11 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
private async Task<string> SendRequestAsync(string uri,
|
private async Task<string> SendRequestAsync(string uri,
|
||||||
X509Certificate cert = null)
|
X509Certificate cert = null)
|
||||||
{
|
{
|
||||||
WebRequestHandler handler = new WebRequestHandler();
|
#if DNX451
|
||||||
|
var handler = new WebRequestHandler();
|
||||||
|
#else
|
||||||
|
var handler = new WinHttpHandler();
|
||||||
|
#endif
|
||||||
handler.ServerCertificateValidationCallback = (a, b, c, d) => true;
|
handler.ServerCertificateValidationCallback = (a, b, c, d) => true;
|
||||||
if (cert != null)
|
if (cert != null)
|
||||||
{
|
{
|
||||||
|
|
@ -129,7 +133,11 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
|
|
||||||
private async Task<string> SendRequestAsync(string uri, string upload)
|
private async Task<string> SendRequestAsync(string uri, string upload)
|
||||||
{
|
{
|
||||||
WebRequestHandler handler = new WebRequestHandler();
|
#if DNX451
|
||||||
|
var handler = new WebRequestHandler();
|
||||||
|
#else
|
||||||
|
var handler = new WinHttpHandler();
|
||||||
|
#endif
|
||||||
handler.ServerCertificateValidationCallback = (a, b, c, d) => true;
|
handler.ServerCertificateValidationCallback = (a, b, c, d) => true;
|
||||||
using (HttpClient client = new HttpClient(handler))
|
using (HttpClient client = new HttpClient(handler))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.Http.Features;
|
using Microsoft.AspNet.Http.Features;
|
||||||
using Microsoft.AspNet.Http.Internal;
|
|
||||||
using Microsoft.AspNet.Testing.xunit;
|
using Microsoft.AspNet.Testing.xunit;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
@ -218,6 +217,7 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
// Connect with a socket
|
// Connect with a socket
|
||||||
Uri uri = new Uri(address);
|
Uri uri = new Uri(address);
|
||||||
TcpClient client = new TcpClient();
|
TcpClient client = new TcpClient();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await client.ConnectAsync(uri.Host, uri.Port);
|
await client.ConnectAsync(uri.Host, uri.Port);
|
||||||
|
|
@ -235,7 +235,7 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
client.Close();
|
((IDisposable)client).Dispose();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -191,6 +191,7 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
// Connect with a socket
|
// Connect with a socket
|
||||||
Uri uri = new Uri(address);
|
Uri uri = new Uri(address);
|
||||||
TcpClient client = new TcpClient();
|
TcpClient client = new TcpClient();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await client.ConnectAsync(uri.Host, uri.Port);
|
await client.ConnectAsync(uri.Host, uri.Port);
|
||||||
|
|
@ -204,7 +205,7 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
client.Close();
|
((IDisposable)client).Dispose();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
|
|
||||||
byte[] response = new byte[1024 * 5];
|
byte[] response = new byte[1024 * 5];
|
||||||
await Task.Run(() => socket.Receive(response));
|
await Task.Run(() => socket.Receive(response));
|
||||||
socket.Close();
|
socket.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Http.Features;
|
using Microsoft.AspNet.Http.Features;
|
||||||
using Microsoft.AspNet.Http.Internal;
|
using Microsoft.AspNet.Http.Internal;
|
||||||
|
using Microsoft.AspNet.Testing.xunit;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Server.WebListener
|
namespace Microsoft.AspNet.Server.WebListener
|
||||||
|
|
@ -78,7 +79,7 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
string address;
|
string address;
|
||||||
using (Utilities.CreateHttpServer(out address, async httpContext =>
|
using (Utilities.CreateHttpServer(out address, async httpContext =>
|
||||||
{
|
{
|
||||||
httpContext.Response.Headers["transfeR-Encoding"] = " CHunked ";
|
httpContext.Response.Headers["transfeR-Encoding"] = "CHunked";
|
||||||
Stream stream = httpContext.Response.Body;
|
Stream stream = httpContext.Response.Body;
|
||||||
var responseBytes = Encoding.ASCII.GetBytes("10\r\nManually Chunked\r\n0\r\n\r\n");
|
var responseBytes = Encoding.ASCII.GetBytes("10\r\nManually Chunked\r\n0\r\n\r\n");
|
||||||
await stream.WriteAsync(responseBytes, 0, responseBytes.Length);
|
await stream.WriteAsync(responseBytes, 0, responseBytes.Length);
|
||||||
|
|
@ -98,13 +99,17 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
public async Task ResponseBody_WriteContentLength_PassedThrough()
|
public async Task ResponseBody_WriteContentLength_PassedThrough()
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
using (Utilities.CreateHttpServer(out address, httpContext =>
|
using (Utilities.CreateHttpServer(out address, async httpContext =>
|
||||||
{
|
{
|
||||||
httpContext.Response.Headers["Content-lenGth"] = " 30 ";
|
httpContext.Response.Headers["Content-lenGth"] = " 30 ";
|
||||||
Stream stream = httpContext.Response.Body;
|
Stream stream = httpContext.Response.Body;
|
||||||
|
#if DNX451
|
||||||
stream.EndWrite(stream.BeginWrite(new byte[10], 0, 10, null, null));
|
stream.EndWrite(stream.BeginWrite(new byte[10], 0, 10, null, null));
|
||||||
|
#else
|
||||||
|
await stream.WriteAsync(new byte[10], 0, 10);
|
||||||
|
#endif
|
||||||
stream.Write(new byte[10], 0, 10);
|
stream.Write(new byte[10], 0, 10);
|
||||||
return stream.WriteAsync(new byte[10], 0, 10);
|
await stream.WriteAsync(new byte[10], 0, 10);
|
||||||
}))
|
}))
|
||||||
{
|
{
|
||||||
HttpResponseMessage response = await SendRequestAsync(address);
|
HttpResponseMessage response = await SendRequestAsync(address);
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
Assert.Equal(0, response.ContentLength);
|
Assert.Equal(0, response.ContentLength);
|
||||||
Assert.NotNull(response.Headers["Date"]);
|
Assert.NotNull(response.Headers["Date"]);
|
||||||
Assert.Equal("Microsoft-HTTPAPI/2.0", response.Headers["Server"]);
|
Assert.Equal("Microsoft-HTTPAPI/2.0", response.Headers["Server"]);
|
||||||
Assert.Equal(new string[] { "custom1" }, response.Headers.GetValues("WWW-Authenticate"));
|
Assert.Equal("custom1", response.Headers["WWW-Authenticate"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,7 +94,11 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
Assert.Equal(0, response.ContentLength);
|
Assert.Equal(0, response.ContentLength);
|
||||||
Assert.NotNull(response.Headers["Date"]);
|
Assert.NotNull(response.Headers["Date"]);
|
||||||
Assert.Equal("Microsoft-HTTPAPI/2.0", response.Headers["Server"]);
|
Assert.Equal("Microsoft-HTTPAPI/2.0", response.Headers["Server"]);
|
||||||
|
#if DNXCORE50 // WebHeaderCollection.GetValues() not available in CoreCLR.
|
||||||
|
Assert.Equal("custom1, and custom2, custom3", response.Headers["WWW-Authenticate"]);
|
||||||
|
#else
|
||||||
Assert.Equal(new string[] { "custom1, and custom2", "custom3" }, response.Headers.GetValues("WWW-Authenticate"));
|
Assert.Equal(new string[] { "custom1, and custom2", "custom3" }, response.Headers.GetValues("WWW-Authenticate"));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,7 +122,11 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
Assert.Equal(0, response.ContentLength);
|
Assert.Equal(0, response.ContentLength);
|
||||||
Assert.NotNull(response.Headers["Date"]);
|
Assert.NotNull(response.Headers["Date"]);
|
||||||
Assert.Equal("Microsoft-HTTPAPI/2.0", response.Headers["Server"]);
|
Assert.Equal("Microsoft-HTTPAPI/2.0", response.Headers["Server"]);
|
||||||
|
#if DNXCORE50 // WebHeaderCollection.GetValues() not available in CoreCLR.
|
||||||
|
Assert.Equal("custom1, and custom2, custom3", response.Headers["Custom-Header1"]);
|
||||||
|
#else
|
||||||
Assert.Equal(new string[] { "custom1, and custom2", "custom3" }, response.Headers.GetValues("Custom-Header1"));
|
Assert.Equal(new string[] { "custom1, and custom2", "custom3" }, response.Headers.GetValues("Custom-Header1"));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Http.Features;
|
using Microsoft.AspNet.Http.Features;
|
||||||
using Microsoft.AspNet.Http.Internal;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Server.WebListener
|
namespace Microsoft.AspNet.Server.WebListener
|
||||||
|
|
@ -38,7 +37,7 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
|
|
||||||
public ResponseSendFileTests()
|
public ResponseSendFileTests()
|
||||||
{
|
{
|
||||||
AbsoluteFilePath = Directory.GetFiles(Environment.CurrentDirectory).First();
|
AbsoluteFilePath = Directory.GetFiles(Directory.GetCurrentDirectory()).First();
|
||||||
RelativeFilePath = Path.GetFileName(AbsoluteFilePath);
|
RelativeFilePath = Path.GetFileName(AbsoluteFilePath);
|
||||||
FileLength = new FileInfo(AbsoluteFilePath).Length;
|
FileLength = new FileInfo(AbsoluteFilePath).Length;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -207,7 +207,11 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
using (Socket socket = await SendHungRequestAsync("GET", address))
|
using (Socket socket = await SendHungRequestAsync("GET", address))
|
||||||
{
|
{
|
||||||
Assert.True(received.WaitOne(interval), "Receive Timeout");
|
Assert.True(received.WaitOne(interval), "Receive Timeout");
|
||||||
socket.Close(0); // Force a RST
|
|
||||||
|
// Force a RST
|
||||||
|
socket.LingerState = new LingerOption(true, 0);
|
||||||
|
socket.Dispose();
|
||||||
|
|
||||||
aborted.Set();
|
aborted.Set();
|
||||||
}
|
}
|
||||||
Assert.True(canceled.WaitOne(interval), "canceled");
|
Assert.True(canceled.WaitOne(interval), "canceled");
|
||||||
|
|
@ -267,7 +271,6 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
|
|
||||||
private async Task<string> SendRequestAsync(string uri)
|
private async Task<string> SendRequestAsync(string uri)
|
||||||
{
|
{
|
||||||
ServicePointManager.DefaultConnectionLimit = 100;
|
|
||||||
using (HttpClient client = new HttpClient())
|
using (HttpClient client = new HttpClient())
|
||||||
{
|
{
|
||||||
return await client.GetStringAsync(uri);
|
return await client.GetStringAsync(uri);
|
||||||
|
|
@ -289,6 +292,7 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
// Connect with a socket
|
// Connect with a socket
|
||||||
Uri uri = new Uri(address);
|
Uri uri = new Uri(address);
|
||||||
TcpClient client = new TcpClient();
|
TcpClient client = new TcpClient();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await client.ConnectAsync(uri.Host, uri.Port);
|
await client.ConnectAsync(uri.Host, uri.Port);
|
||||||
|
|
@ -297,13 +301,13 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
// Send an HTTP GET request
|
// Send an HTTP GET request
|
||||||
byte[] requestBytes = BuildGetRequest(method, uri);
|
byte[] requestBytes = BuildGetRequest(method, uri);
|
||||||
await stream.WriteAsync(requestBytes, 0, requestBytes.Length);
|
await stream.WriteAsync(requestBytes, 0, requestBytes.Length);
|
||||||
|
|
||||||
// Return the opaque network stream
|
// Return the opaque network stream
|
||||||
return client.Client;
|
return client.Client;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
client.Close();
|
((IDisposable)client).Dispose();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,13 @@
|
||||||
"System.Net.Http": "",
|
"System.Net.Http": "",
|
||||||
"System.Net.Http.WebRequest": ""
|
"System.Net.Http.WebRequest": ""
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"dnxcore50": {
|
||||||
|
"dependencies": {
|
||||||
|
"System.Net.Http.WinHttpHandler": "4.0.0-*",
|
||||||
|
"System.Net.Requests": "4.0.11-*",
|
||||||
|
"System.Net.WebHeaderCollection": "4.0.1-*"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,11 +44,12 @@ namespace Microsoft.Net.Http.Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[ConditionalTheory]
|
||||||
[InlineData(AuthenticationSchemes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationSchemes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationType.Digest)] // TODO: Not implemented
|
// [InlineData(AuthenticationType.Digest)] // TODO: Not implemented
|
||||||
[InlineData(AuthenticationSchemes.Basic)]
|
[InlineData(AuthenticationSchemes.Basic)]
|
||||||
|
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "HttpClientHandler issue (https://github.com/dotnet/corefx/issues/5045).")]
|
||||||
public async Task AuthType_RequireAuth_ChallengesAdded(AuthenticationSchemes authType)
|
public async Task AuthType_RequireAuth_ChallengesAdded(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
|
|
@ -57,18 +58,18 @@ namespace Microsoft.Net.Http.Server
|
||||||
Task<HttpResponseMessage> responseTask = SendRequestAsync(address);
|
Task<HttpResponseMessage> responseTask = SendRequestAsync(address);
|
||||||
|
|
||||||
var contextTask = server.GetContextAsync(); // Fails when the server shuts down, the challenge happens internally.
|
var contextTask = server.GetContextAsync(); // Fails when the server shuts down, the challenge happens internally.
|
||||||
|
|
||||||
var response = await responseTask;
|
var response = await responseTask;
|
||||||
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
|
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
|
||||||
Assert.Equal(authType.ToString(), response.Headers.WwwAuthenticate.ToString(), StringComparer.OrdinalIgnoreCase);
|
Assert.Equal(authType.ToString(), response.Headers.WwwAuthenticate.ToString(), StringComparer.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[ConditionalTheory]
|
||||||
[InlineData(AuthenticationSchemes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationSchemes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented
|
// [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented
|
||||||
[InlineData(AuthenticationSchemes.Basic)]
|
[InlineData(AuthenticationSchemes.Basic)]
|
||||||
|
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "HttpClientHandler issue (https://github.com/dotnet/corefx/issues/5045).")]
|
||||||
public async Task AuthType_AllowAnonymousButSpecify401_ChallengesAdded(AuthenticationSchemes authType)
|
public async Task AuthType_AllowAnonymousButSpecify401_ChallengesAdded(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
|
|
@ -89,7 +90,8 @@ namespace Microsoft.Net.Http.Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[ConditionalFact]
|
||||||
|
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "HttpClientHandler issue (https://github.com/dotnet/corefx/issues/5045).")]
|
||||||
public async Task MultipleAuthTypes_AllowAnonymousButSpecify401_ChallengesAdded()
|
public async Task MultipleAuthTypes_AllowAnonymousButSpecify401_ChallengesAdded()
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
|
|
@ -216,7 +218,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
{
|
{
|
||||||
HttpClientHandler handler = new HttpClientHandler();
|
HttpClientHandler handler = new HttpClientHandler();
|
||||||
handler.UseDefaultCredentials = useDefaultCredentials;
|
handler.UseDefaultCredentials = useDefaultCredentials;
|
||||||
using (HttpClient client = new HttpClient(handler))
|
using (HttpClient client = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(5) })
|
||||||
{
|
{
|
||||||
return await client.GetAsync(uri);
|
return await client.GetAsync(uri);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,11 @@ namespace Microsoft.Net.Http.Server
|
||||||
private async Task<string> SendRequestAsync(string uri,
|
private async Task<string> SendRequestAsync(string uri,
|
||||||
X509Certificate cert = null)
|
X509Certificate cert = null)
|
||||||
{
|
{
|
||||||
|
#if DNX451
|
||||||
WebRequestHandler handler = new WebRequestHandler();
|
WebRequestHandler handler = new WebRequestHandler();
|
||||||
|
#else
|
||||||
|
WinHttpHandler handler = new WinHttpHandler();
|
||||||
|
#endif
|
||||||
handler.ServerCertificateValidationCallback = (a, b, c, d) => true;
|
handler.ServerCertificateValidationCallback = (a, b, c, d) => true;
|
||||||
if (cert != null)
|
if (cert != null)
|
||||||
{
|
{
|
||||||
|
|
@ -121,7 +125,11 @@ namespace Microsoft.Net.Http.Server
|
||||||
|
|
||||||
private async Task<string> SendRequestAsync(string uri, string upload)
|
private async Task<string> SendRequestAsync(string uri, string upload)
|
||||||
{
|
{
|
||||||
|
#if DNX451
|
||||||
WebRequestHandler handler = new WebRequestHandler();
|
WebRequestHandler handler = new WebRequestHandler();
|
||||||
|
#else
|
||||||
|
WinHttpHandler handler = new WinHttpHandler();
|
||||||
|
#endif
|
||||||
handler.ServerCertificateValidationCallback = (a, b, c, d) => true;
|
handler.ServerCertificateValidationCallback = (a, b, c, d) => true;
|
||||||
using (HttpClient client = new HttpClient(handler))
|
using (HttpClient client = new HttpClient(handler))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
client.Close();
|
((IDisposable)client).Dispose();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -352,7 +352,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
client.Close();
|
((IDisposable)client).Dispose();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
|
|
||||||
byte[] response = new byte[1024 * 5];
|
byte[] response = new byte[1024 * 5];
|
||||||
await Task.Run(() => socket.Receive(response));
|
await Task.Run(() => socket.Receive(response));
|
||||||
socket.Close();
|
socket.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -8,6 +8,7 @@ using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNet.Testing.xunit;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.Net.Http.Server
|
namespace Microsoft.Net.Http.Server
|
||||||
|
|
@ -94,7 +95,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
Task<HttpResponseMessage> responseTask = SendRequestAsync(address);
|
Task<HttpResponseMessage> responseTask = SendRequestAsync(address);
|
||||||
|
|
||||||
var context = await server.GetContextAsync();
|
var context = await server.GetContextAsync();
|
||||||
context.Response.Headers["transfeR-Encoding"] = " CHunked ";
|
context.Response.Headers["transfeR-Encoding"] = "CHunked";
|
||||||
Stream stream = context.Response.Body;
|
Stream stream = context.Response.Body;
|
||||||
var responseBytes = Encoding.ASCII.GetBytes("10\r\nManually Chunked\r\n0\r\n\r\n");
|
var responseBytes = Encoding.ASCII.GetBytes("10\r\nManually Chunked\r\n0\r\n\r\n");
|
||||||
await stream.WriteAsync(responseBytes, 0, responseBytes.Length);
|
await stream.WriteAsync(responseBytes, 0, responseBytes.Length);
|
||||||
|
|
@ -121,7 +122,11 @@ namespace Microsoft.Net.Http.Server
|
||||||
var context = await server.GetContextAsync();
|
var context = await server.GetContextAsync();
|
||||||
context.Response.Headers["Content-lenGth"] = " 30 ";
|
context.Response.Headers["Content-lenGth"] = " 30 ";
|
||||||
Stream stream = context.Response.Body;
|
Stream stream = context.Response.Body;
|
||||||
|
#if DNX451
|
||||||
stream.EndWrite(stream.BeginWrite(new byte[10], 0, 10, null, null));
|
stream.EndWrite(stream.BeginWrite(new byte[10], 0, 10, null, null));
|
||||||
|
#else
|
||||||
|
await stream.WriteAsync(new byte[10], 0, 10);
|
||||||
|
#endif
|
||||||
stream.Write(new byte[10], 0, 10);
|
stream.Write(new byte[10], 0, 10);
|
||||||
await stream.WriteAsync(new byte[10], 0, 10);
|
await stream.WriteAsync(new byte[10], 0, 10);
|
||||||
context.Dispose();
|
context.Dispose();
|
||||||
|
|
@ -148,12 +153,12 @@ namespace Microsoft.Net.Http.Server
|
||||||
var context = await server.GetContextAsync();
|
var context = await server.GetContextAsync();
|
||||||
context.Response.Headers["Content-lenGth"] = " 20 ";
|
context.Response.Headers["Content-lenGth"] = " 20 ";
|
||||||
context.Dispose();
|
context.Dispose();
|
||||||
|
#if !DNXCORE50
|
||||||
// HttpClient retries the request because it didn't get a response.
|
// HttpClient retries the request because it didn't get a response.
|
||||||
context = await server.GetContextAsync();
|
context = await server.GetContextAsync();
|
||||||
context.Response.Headers["Content-lenGth"] = " 20 ";
|
context.Response.Headers["Content-lenGth"] = " 20 ";
|
||||||
context.Dispose();
|
context.Dispose();
|
||||||
|
#endif
|
||||||
await Assert.ThrowsAsync<HttpRequestException>(() => responseTask);
|
await Assert.ThrowsAsync<HttpRequestException>(() => responseTask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -170,13 +175,13 @@ namespace Microsoft.Net.Http.Server
|
||||||
context.Response.Headers["Content-lenGth"] = " 20 ";
|
context.Response.Headers["Content-lenGth"] = " 20 ";
|
||||||
context.Response.Body.Write(new byte[5], 0, 5);
|
context.Response.Body.Write(new byte[5], 0, 5);
|
||||||
context.Dispose();
|
context.Dispose();
|
||||||
|
#if !DNXCORE50
|
||||||
// HttpClient retries the request because it didn't get a response.
|
// HttpClient retries the request because it didn't get a response.
|
||||||
context = await server.GetContextAsync();
|
context = await server.GetContextAsync();
|
||||||
context.Response.Headers["Content-lenGth"] = " 20 ";
|
context.Response.Headers["Content-lenGth"] = " 20 ";
|
||||||
context.Response.Body.Write(new byte[5], 0, 5);
|
context.Response.Body.Write(new byte[5], 0, 5);
|
||||||
context.Dispose();
|
context.Dispose();
|
||||||
|
#endif
|
||||||
await Assert.ThrowsAsync<HttpRequestException>(() => responseTask);
|
await Assert.ThrowsAsync<HttpRequestException>(() => responseTask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -194,14 +199,14 @@ namespace Microsoft.Net.Http.Server
|
||||||
context.Response.Body.Write(new byte[5], 0, 5);
|
context.Response.Body.Write(new byte[5], 0, 5);
|
||||||
Assert.Throws<InvalidOperationException>(() => context.Response.Body.Write(new byte[6], 0, 6));
|
Assert.Throws<InvalidOperationException>(() => context.Response.Body.Write(new byte[6], 0, 6));
|
||||||
context.Dispose();
|
context.Dispose();
|
||||||
|
#if !DNXCORE50
|
||||||
// HttpClient retries the request because it didn't get a response.
|
// HttpClient retries the request because it didn't get a response.
|
||||||
context = await server.GetContextAsync();
|
context = await server.GetContextAsync();
|
||||||
context.Response.Headers["Content-lenGth"] = " 10 ";
|
context.Response.Headers["Content-lenGth"] = " 10 ";
|
||||||
context.Response.Body.Write(new byte[5], 0, 5);
|
context.Response.Body.Write(new byte[5], 0, 5);
|
||||||
Assert.Throws<InvalidOperationException>(() => context.Response.Body.Write(new byte[6], 0, 6));
|
Assert.Throws<InvalidOperationException>(() => context.Response.Body.Write(new byte[6], 0, 6));
|
||||||
context.Dispose();
|
context.Dispose();
|
||||||
|
#endif
|
||||||
await Assert.ThrowsAsync<HttpRequestException>(() => responseTask);
|
await Assert.ThrowsAsync<HttpRequestException>(() => responseTask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,10 @@ using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNet.Testing.xunit;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.Net.Http.Server.FunctionalTests
|
namespace Microsoft.Net.Http.Server
|
||||||
{
|
{
|
||||||
public class ResponseCachingTests
|
public class ResponseCachingTests
|
||||||
{
|
{
|
||||||
|
|
@ -17,7 +18,7 @@ namespace Microsoft.Net.Http.Server.FunctionalTests
|
||||||
|
|
||||||
public ResponseCachingTests()
|
public ResponseCachingTests()
|
||||||
{
|
{
|
||||||
_absoluteFilePath = Directory.GetFiles(Environment.CurrentDirectory).First();
|
_absoluteFilePath = Directory.GetFiles(Directory.GetCurrentDirectory()).First();
|
||||||
_fileLength = new FileInfo(_absoluteFilePath).Length;
|
_fileLength = new FileInfo(_absoluteFilePath).Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -473,6 +474,12 @@ namespace Microsoft.Net.Http.Server.FunctionalTests
|
||||||
// Http.Sys will cache any status code.
|
// Http.Sys will cache any status code.
|
||||||
for (int status = 200; status < 600; status++)
|
for (int status = 200; status < 600; status++)
|
||||||
{
|
{
|
||||||
|
// 407 (Proxy Authentication Required) makes CoreCLR's HttpClient throw
|
||||||
|
if (status == 407)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var responseTask = SendRequestAsync(address + status);
|
var responseTask = SendRequestAsync(address + status);
|
||||||
|
|
||||||
var context = await server.GetContextAsync();
|
var context = await server.GetContextAsync();
|
||||||
|
|
@ -935,7 +942,8 @@ namespace Microsoft.Net.Http.Server.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://tools.ietf.org/html/rfc7233#section-4.1
|
// http://tools.ietf.org/html/rfc7233#section-4.1
|
||||||
[Fact]
|
[ConditionalFact]
|
||||||
|
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "Cached response contains duplicate Content-Length headers (#167).")]
|
||||||
public async Task Caching_RequestRangeFromCache_RangeServedFromCache()
|
public async Task Caching_RequestRangeFromCache_RangeServedFromCache()
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
|
|
@ -956,11 +964,11 @@ namespace Microsoft.Net.Http.Server.FunctionalTests
|
||||||
Assert.Equal("1", response.Headers.GetValues("x-request-count").FirstOrDefault());
|
Assert.Equal("1", response.Headers.GetValues("x-request-count").FirstOrDefault());
|
||||||
Assert.Equal(new byte[100], await response.Content.ReadAsByteArrayAsync());
|
Assert.Equal(new byte[100], await response.Content.ReadAsByteArrayAsync());
|
||||||
|
|
||||||
response = await SendRequestAsync(address, "GET", "Range", "bytes=0-10");
|
response = await SendRequestAsync(address, "GET", "Range", "bytes=0-10", HttpCompletionOption.ResponseHeadersRead);
|
||||||
Assert.Equal(206, (int)response.StatusCode);
|
Assert.Equal(206, (int)response.StatusCode);
|
||||||
Assert.Equal("1", response.Headers.GetValues("x-request-count").FirstOrDefault());
|
Assert.Equal("1", response.Headers.GetValues("x-request-count").FirstOrDefault());
|
||||||
Assert.Equal("bytes 0-10/100", response.Content.Headers.GetValues("content-range").FirstOrDefault());
|
Assert.Equal("bytes 0-10/100", response.Content.Headers.GetValues("content-range").FirstOrDefault());
|
||||||
Assert.Equal(new byte[11], await response.Content.ReadAsByteArrayAsync());
|
Assert.Equal(11, response.Content.Headers.ContentLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -993,7 +1001,8 @@ namespace Microsoft.Net.Http.Server.FunctionalTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[ConditionalFact]
|
||||||
|
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "Cached response contains duplicate Content-Length headers (#167).")]
|
||||||
public async Task Caching_RequestRangeFromCachedFile_ServedFromCache()
|
public async Task Caching_RequestRangeFromCachedFile_ServedFromCache()
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
|
|
@ -1017,7 +1026,7 @@ namespace Microsoft.Net.Http.Server.FunctionalTests
|
||||||
|
|
||||||
// Send a second request and make sure we get the same response (without listening for one on the server).
|
// Send a second request and make sure we get the same response (without listening for one on the server).
|
||||||
var rangeLength = responseLength / 2;
|
var rangeLength = responseLength / 2;
|
||||||
response = await SendRequestAsync(address, "GET", "Range", "bytes=0-" + (rangeLength - 1));
|
response = await SendRequestAsync(address, "GET", "Range", "bytes=0-" + (rangeLength - 1), HttpCompletionOption.ResponseHeadersRead);
|
||||||
Assert.Equal(206, (int)response.StatusCode);
|
Assert.Equal(206, (int)response.StatusCode);
|
||||||
Assert.Equal("1", response.Headers.GetValues("x-request-count").FirstOrDefault());
|
Assert.Equal("1", response.Headers.GetValues("x-request-count").FirstOrDefault());
|
||||||
Assert.Equal(rangeLength, response.Content.Headers.ContentLength);
|
Assert.Equal(rangeLength, response.Content.Headers.ContentLength);
|
||||||
|
|
@ -1046,26 +1055,28 @@ namespace Microsoft.Net.Http.Server.FunctionalTests
|
||||||
Assert.Equal(200, (int)response.StatusCode);
|
Assert.Equal(200, (int)response.StatusCode);
|
||||||
Assert.Equal("1", response.Headers.GetValues("x-request-count").FirstOrDefault());
|
Assert.Equal("1", response.Headers.GetValues("x-request-count").FirstOrDefault());
|
||||||
Assert.Equal(responseLength, response.Content.Headers.ContentLength);
|
Assert.Equal(responseLength, response.Content.Headers.ContentLength);
|
||||||
|
|
||||||
// Send a second request and make sure we get the same response (without listening for one on the server).
|
// Send a second request and make sure we get the same response (without listening for one on the server).
|
||||||
var rangeLength = responseLength / 4;
|
var rangeLength = responseLength / 4;
|
||||||
response = await SendRequestAsync(address, "GET", "Range", "bytes=0-" + (rangeLength - 1) + "," + rangeLength + "-" + (rangeLength + rangeLength - 1));
|
response = await SendRequestAsync(address, "GET", "Range", "bytes=0-" + (rangeLength - 1) + "," + rangeLength + "-" + (rangeLength + rangeLength - 1), HttpCompletionOption.ResponseHeadersRead);
|
||||||
Assert.Equal(206, (int)response.StatusCode);
|
Assert.Equal(206, (int)response.StatusCode);
|
||||||
Assert.Equal("1", response.Headers.GetValues("x-request-count").FirstOrDefault());
|
Assert.Equal("1", response.Headers.GetValues("x-request-count").FirstOrDefault());
|
||||||
Assert.True(response.Content.Headers.GetValues("content-type").First().StartsWith("multipart/byteranges;"));
|
Assert.True(response.Content.Headers.GetValues("content-type").First().StartsWith("multipart/byteranges;"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<HttpResponseMessage> SendRequestAsync(string uri, string method = "GET", string extraHeader = null, string extraHeaderValue = null)
|
private async Task<HttpResponseMessage> SendRequestAsync(string uri, string method = "GET", string extraHeader = null, string extraHeaderValue = null, HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead)
|
||||||
{
|
{
|
||||||
using (var client = new HttpClient() { Timeout = TimeSpan.FromSeconds(5) })
|
using (var handler = new HttpClientHandler() { AllowAutoRedirect = false })
|
||||||
{
|
{
|
||||||
var request = new HttpRequestMessage(new HttpMethod(method), uri);
|
using (var client = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(5) })
|
||||||
if (!string.IsNullOrEmpty(extraHeader))
|
|
||||||
{
|
{
|
||||||
request.Headers.Add(extraHeader, extraHeaderValue);
|
var request = new HttpRequestMessage(new HttpMethod(method), uri);
|
||||||
|
if (!string.IsNullOrEmpty(extraHeader))
|
||||||
|
{
|
||||||
|
request.Headers.Add(extraHeader, extraHeaderValue);
|
||||||
|
}
|
||||||
|
return await client.SendAsync(request, httpCompletionOption);
|
||||||
}
|
}
|
||||||
return await client.SendAsync(request);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
Assert.Equal(0, response.ContentLength);
|
Assert.Equal(0, response.ContentLength);
|
||||||
Assert.NotNull(response.Headers["Date"]);
|
Assert.NotNull(response.Headers["Date"]);
|
||||||
Assert.Equal("Microsoft-HTTPAPI/2.0", response.Headers["Server"]);
|
Assert.Equal("Microsoft-HTTPAPI/2.0", response.Headers["Server"]);
|
||||||
Assert.Equal(new string[] { "custom1" }, response.Headers.GetValues("WWW-Authenticate"));
|
Assert.Equal("custom1", response.Headers["WWW-Authenticate"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -217,7 +217,11 @@ namespace Microsoft.Net.Http.Server
|
||||||
Assert.Equal(0, response.ContentLength);
|
Assert.Equal(0, response.ContentLength);
|
||||||
Assert.NotNull(response.Headers["Date"]);
|
Assert.NotNull(response.Headers["Date"]);
|
||||||
Assert.Equal("Microsoft-HTTPAPI/2.0", response.Headers["Server"]);
|
Assert.Equal("Microsoft-HTTPAPI/2.0", response.Headers["Server"]);
|
||||||
|
#if DNXCORE50 // WebHeaderCollection.GetValues() not available in CoreCLR.
|
||||||
|
Assert.Equal("custom1, and custom2, custom3", response.Headers["WWW-Authenticate"]);
|
||||||
|
#else
|
||||||
Assert.Equal(new string[] { "custom1, and custom2", "custom3" }, response.Headers.GetValues("WWW-Authenticate"));
|
Assert.Equal(new string[] { "custom1, and custom2", "custom3" }, response.Headers.GetValues("WWW-Authenticate"));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -242,7 +246,11 @@ namespace Microsoft.Net.Http.Server
|
||||||
Assert.Equal(0, response.ContentLength);
|
Assert.Equal(0, response.ContentLength);
|
||||||
Assert.NotNull(response.Headers["Date"]);
|
Assert.NotNull(response.Headers["Date"]);
|
||||||
Assert.Equal("Microsoft-HTTPAPI/2.0", response.Headers["Server"]);
|
Assert.Equal("Microsoft-HTTPAPI/2.0", response.Headers["Server"]);
|
||||||
|
#if DNXCORE50 // WebHeaderCollection.GetValues() not available in CoreCLR.
|
||||||
|
Assert.Equal("custom1, and custom2, custom3", response.Headers["Custom-Header1"]);
|
||||||
|
#else
|
||||||
Assert.Equal(new string[] { "custom1, and custom2", "custom3" }, response.Headers.GetValues("Custom-Header1"));
|
Assert.Equal(new string[] { "custom1, and custom2", "custom3" }, response.Headers.GetValues("Custom-Header1"));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
|
|
||||||
public ResponseSendFileTests()
|
public ResponseSendFileTests()
|
||||||
{
|
{
|
||||||
AbsoluteFilePath = Directory.GetFiles(Environment.CurrentDirectory).First();
|
AbsoluteFilePath = Directory.GetFiles(Directory.GetCurrentDirectory()).First();
|
||||||
RelativeFilePath = Path.GetFileName(AbsoluteFilePath);
|
RelativeFilePath = Path.GetFileName(AbsoluteFilePath);
|
||||||
FileLength = new FileInfo(AbsoluteFilePath).Length;
|
FileLength = new FileInfo(AbsoluteFilePath).Length;
|
||||||
}
|
}
|
||||||
|
|
@ -205,9 +205,9 @@ namespace Microsoft.Net.Http.Server
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ResponseSendFile_EmptyFileCountUnspecified_SetsChunkedAndFlushesHeaders()
|
public async Task ResponseSendFile_EmptyFileCountUnspecified_SetsChunkedAndFlushesHeaders()
|
||||||
{
|
{
|
||||||
var emptyFilePath = Path.Combine(Environment.CurrentDirectory, "zz_" + Guid.NewGuid().ToString() + "EmptyTestFile.txt");
|
var emptyFilePath = Path.Combine(Directory.GetCurrentDirectory(), "zz_" + Guid.NewGuid().ToString() + "EmptyTestFile.txt");
|
||||||
var emptyFile = File.Create(emptyFilePath, 1024);
|
var emptyFile = File.Create(emptyFilePath, 1024);
|
||||||
emptyFile.Close();
|
emptyFile.Dispose();
|
||||||
|
|
||||||
string address;
|
string address;
|
||||||
using (var server = Utilities.CreateHttpServer(out address))
|
using (var server = Utilities.CreateHttpServer(out address))
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNet.Testing.xunit;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.Net.Http.Server
|
namespace Microsoft.Net.Http.Server
|
||||||
|
|
@ -122,11 +123,11 @@ namespace Microsoft.Net.Http.Server
|
||||||
context.Abort();
|
context.Abort();
|
||||||
Assert.True(canceled.WaitOne(interval), "Aborted");
|
Assert.True(canceled.WaitOne(interval), "Aborted");
|
||||||
Assert.True(ct.IsCancellationRequested, "IsCancellationRequested");
|
Assert.True(ct.IsCancellationRequested, "IsCancellationRequested");
|
||||||
|
#if !DNXCORE50
|
||||||
// HttpClient re-tries the request because it doesn't know if the request was received.
|
// HttpClient re-tries the request because it doesn't know if the request was received.
|
||||||
context = await server.GetContextAsync();
|
context = await server.GetContextAsync();
|
||||||
context.Abort();
|
context.Abort();
|
||||||
|
#endif
|
||||||
await Assert.ThrowsAsync<HttpRequestException>(() => responseTask);
|
await Assert.ThrowsAsync<HttpRequestException>(() => responseTask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -246,7 +247,6 @@ namespace Microsoft.Net.Http.Server
|
||||||
|
|
||||||
private async Task<string> SendRequestAsync(string uri)
|
private async Task<string> SendRequestAsync(string uri)
|
||||||
{
|
{
|
||||||
ServicePointManager.DefaultConnectionLimit = 100;
|
|
||||||
using (HttpClient client = new HttpClient())
|
using (HttpClient client = new HttpClient())
|
||||||
{
|
{
|
||||||
return await client.GetStringAsync(uri);
|
return await client.GetStringAsync(uri);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
// 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 System;
|
using System;
|
||||||
using System.DirectoryServices.ActiveDirectory;
|
|
||||||
using Microsoft.AspNet.Testing.xunit;
|
using Microsoft.AspNet.Testing.xunit;
|
||||||
|
|
||||||
namespace Microsoft.Net.Http.Server
|
namespace Microsoft.Net.Http.Server
|
||||||
|
|
@ -19,7 +18,9 @@ namespace Microsoft.Net.Http.Server
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return !string.IsNullOrEmpty(Domain.GetComputerDomain().Name);
|
#if DNX451
|
||||||
|
return !string.IsNullOrEmpty(System.DirectoryServices.ActiveDirectory.Domain.GetComputerDomain().Name);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,14 @@
|
||||||
"System.Net.Http": "",
|
"System.Net.Http": "",
|
||||||
"System.Net.Http.WebRequest": ""
|
"System.Net.Http.WebRequest": ""
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"dnxcore50": {
|
||||||
|
"dependencies": {
|
||||||
|
"System.Net.Http": "4.0.1-*",
|
||||||
|
"System.Net.Http.WinHttpHandler": "4.0.0-*",
|
||||||
|
"System.Net.Requests": "4.0.11-*",
|
||||||
|
"System.Net.WebSockets.Client": "4.0.0-*"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue