Enable tests on CoreCLR (#143).

This commit is contained in:
Cesar Blum Silveira 2015-12-16 19:20:18 -08:00
parent fdf0b84136
commit 905b5bcfc2
22 changed files with 143 additions and 61 deletions

View File

@ -21,6 +21,7 @@ using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNet.Http.Features.Authentication;
using Microsoft.AspNet.Testing.xunit;
using Xunit;
using AuthenticationSchemes = Microsoft.Net.Http.Server.AuthenticationSchemes;
@ -52,11 +53,12 @@ namespace Microsoft.AspNet.Server.WebListener
}
}
[Theory]
[ConditionalTheory]
[InlineData(AuthenticationSchemes.Negotiate)]
[InlineData(AuthenticationSchemes.NTLM)]
// [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented
[InlineData(AuthenticationSchemes.Basic)]
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "HttpClientHandler issue (https://github.com/dotnet/corefx/issues/5045).")]
public async Task AuthType_RequireAuth_ChallengesAdded(AuthenticationSchemes authType)
{
string address;
@ -71,11 +73,12 @@ namespace Microsoft.AspNet.Server.WebListener
}
}
[Theory]
[ConditionalTheory]
[InlineData(AuthenticationSchemes.Negotiate)]
[InlineData(AuthenticationSchemes.NTLM)]
// [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented
[InlineData(AuthenticationSchemes.Basic)]
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "HttpClientHandler issue (https://github.com/dotnet/corefx/issues/5045).")]
public async Task AuthType_AllowAnonymousButSpecify401_ChallengesAdded(AuthenticationSchemes authType)
{
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()
{
string address;
@ -293,12 +297,13 @@ namespace Microsoft.AspNet.Server.WebListener
}
}
[Theory]
[ConditionalTheory]
[InlineData(AuthenticationSchemes.Negotiate)]
[InlineData(AuthenticationSchemes.NTLM)]
// [InlineData(AuthenticationSchemes.Digest)]
[InlineData(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)
{
string address;
@ -317,12 +322,13 @@ namespace Microsoft.AspNet.Server.WebListener
}
}
[Theory]
[ConditionalTheory]
[InlineData(AuthenticationSchemes.Negotiate)]
[InlineData(AuthenticationSchemes.NTLM)]
// [InlineData(AuthenticationSchemes.Digest)]
[InlineData(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)
{
string address;
@ -344,11 +350,12 @@ namespace Microsoft.AspNet.Server.WebListener
}
}
[Theory]
[ConditionalTheory]
[InlineData(AuthenticationSchemes.Negotiate)]
[InlineData(AuthenticationSchemes.NTLM)]
// [InlineData(AuthenticationSchemes.Digest)]
[InlineData(AuthenticationSchemes.Basic)]
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "HttpClientHandler issue (https://github.com/dotnet/corefx/issues/5045).")]
public async Task AuthTypes_ChallengeOneAuthType_OneChallengeSent(AuthenticationSchemes authType)
{
string address;

View File

@ -115,7 +115,11 @@ namespace Microsoft.AspNet.Server.WebListener
private async Task<string> SendRequestAsync(string uri,
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;
if (cert != null)
{
@ -129,7 +133,11 @@ namespace Microsoft.AspNet.Server.WebListener
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;
using (HttpClient client = new HttpClient(handler))
{

View File

@ -24,7 +24,6 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Features;
using Microsoft.AspNet.Http.Internal;
using Microsoft.AspNet.Testing.xunit;
using Xunit;
@ -218,6 +217,7 @@ namespace Microsoft.AspNet.Server.WebListener
// Connect with a socket
Uri uri = new Uri(address);
TcpClient client = new TcpClient();
try
{
await client.ConnectAsync(uri.Host, uri.Port);
@ -235,7 +235,7 @@ namespace Microsoft.AspNet.Server.WebListener
}
catch (Exception)
{
client.Close();
((IDisposable)client).Dispose();
throw;
}
}

View File

@ -191,6 +191,7 @@ namespace Microsoft.AspNet.Server.WebListener
// Connect with a socket
Uri uri = new Uri(address);
TcpClient client = new TcpClient();
try
{
await client.ConnectAsync(uri.Host, uri.Port);
@ -204,7 +205,7 @@ namespace Microsoft.AspNet.Server.WebListener
}
catch (Exception)
{
client.Close();
((IDisposable)client).Dispose();
throw;
}
}

View File

@ -107,7 +107,7 @@ namespace Microsoft.AspNet.Server.WebListener
byte[] response = new byte[1024 * 5];
await Task.Run(() => socket.Receive(response));
socket.Close();
socket.Dispose();
}
}
}

View File

@ -25,6 +25,7 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Http.Features;
using Microsoft.AspNet.Http.Internal;
using Microsoft.AspNet.Testing.xunit;
using Xunit;
namespace Microsoft.AspNet.Server.WebListener
@ -78,7 +79,7 @@ namespace Microsoft.AspNet.Server.WebListener
string address;
using (Utilities.CreateHttpServer(out address, async httpContext =>
{
httpContext.Response.Headers["transfeR-Encoding"] = " CHunked ";
httpContext.Response.Headers["transfeR-Encoding"] = "CHunked";
Stream stream = httpContext.Response.Body;
var responseBytes = Encoding.ASCII.GetBytes("10\r\nManually Chunked\r\n0\r\n\r\n");
await stream.WriteAsync(responseBytes, 0, responseBytes.Length);
@ -98,13 +99,17 @@ namespace Microsoft.AspNet.Server.WebListener
public async Task ResponseBody_WriteContentLength_PassedThrough()
{
string address;
using (Utilities.CreateHttpServer(out address, httpContext =>
using (Utilities.CreateHttpServer(out address, async httpContext =>
{
httpContext.Response.Headers["Content-lenGth"] = " 30 ";
Stream stream = httpContext.Response.Body;
#if DNX451
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);
return stream.WriteAsync(new byte[10], 0, 10);
await stream.WriteAsync(new byte[10], 0, 10);
}))
{
HttpResponseMessage response = await SendRequestAsync(address);

View File

@ -70,7 +70,7 @@ namespace Microsoft.AspNet.Server.WebListener
Assert.Equal(0, response.ContentLength);
Assert.NotNull(response.Headers["Date"]);
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.NotNull(response.Headers["Date"]);
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"));
#endif
}
}
@ -118,7 +122,11 @@ namespace Microsoft.AspNet.Server.WebListener
Assert.Equal(0, response.ContentLength);
Assert.NotNull(response.Headers["Date"]);
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"));
#endif
}
}

View File

@ -25,7 +25,6 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Http.Features;
using Microsoft.AspNet.Http.Internal;
using Xunit;
namespace Microsoft.AspNet.Server.WebListener
@ -38,7 +37,7 @@ namespace Microsoft.AspNet.Server.WebListener
public ResponseSendFileTests()
{
AbsoluteFilePath = Directory.GetFiles(Environment.CurrentDirectory).First();
AbsoluteFilePath = Directory.GetFiles(Directory.GetCurrentDirectory()).First();
RelativeFilePath = Path.GetFileName(AbsoluteFilePath);
FileLength = new FileInfo(AbsoluteFilePath).Length;
}

View File

@ -207,7 +207,11 @@ namespace Microsoft.AspNet.Server.WebListener
using (Socket socket = await SendHungRequestAsync("GET", address))
{
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();
}
Assert.True(canceled.WaitOne(interval), "canceled");
@ -267,7 +271,6 @@ namespace Microsoft.AspNet.Server.WebListener
private async Task<string> SendRequestAsync(string uri)
{
ServicePointManager.DefaultConnectionLimit = 100;
using (HttpClient client = new HttpClient())
{
return await client.GetStringAsync(uri);
@ -289,6 +292,7 @@ namespace Microsoft.AspNet.Server.WebListener
// Connect with a socket
Uri uri = new Uri(address);
TcpClient client = new TcpClient();
try
{
await client.ConnectAsync(uri.Host, uri.Port);
@ -297,13 +301,13 @@ namespace Microsoft.AspNet.Server.WebListener
// Send an HTTP GET request
byte[] requestBytes = BuildGetRequest(method, uri);
await stream.WriteAsync(requestBytes, 0, requestBytes.Length);
// Return the opaque network stream
return client.Client;
}
catch (Exception)
{
client.Close();
((IDisposable)client).Dispose();
throw;
}
}

View File

@ -13,6 +13,13 @@
"System.Net.Http": "",
"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-*"
}
}
}
}

View File

@ -44,11 +44,12 @@ namespace Microsoft.Net.Http.Server
}
}
[Theory]
[ConditionalTheory]
[InlineData(AuthenticationSchemes.Negotiate)]
[InlineData(AuthenticationSchemes.NTLM)]
// [InlineData(AuthenticationType.Digest)] // TODO: Not implemented
[InlineData(AuthenticationSchemes.Basic)]
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "HttpClientHandler issue (https://github.com/dotnet/corefx/issues/5045).")]
public async Task AuthType_RequireAuth_ChallengesAdded(AuthenticationSchemes authType)
{
string address;
@ -57,18 +58,18 @@ namespace Microsoft.Net.Http.Server
Task<HttpResponseMessage> responseTask = SendRequestAsync(address);
var contextTask = server.GetContextAsync(); // Fails when the server shuts down, the challenge happens internally.
var response = await responseTask;
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
Assert.Equal(authType.ToString(), response.Headers.WwwAuthenticate.ToString(), StringComparer.OrdinalIgnoreCase);
}
}
[Theory]
[ConditionalTheory]
[InlineData(AuthenticationSchemes.Negotiate)]
[InlineData(AuthenticationSchemes.NTLM)]
// [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented
[InlineData(AuthenticationSchemes.Basic)]
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "HttpClientHandler issue (https://github.com/dotnet/corefx/issues/5045).")]
public async Task AuthType_AllowAnonymousButSpecify401_ChallengesAdded(AuthenticationSchemes authType)
{
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()
{
string address;
@ -216,7 +218,7 @@ namespace Microsoft.Net.Http.Server
{
HttpClientHandler handler = new HttpClientHandler();
handler.UseDefaultCredentials = useDefaultCredentials;
using (HttpClient client = new HttpClient(handler))
using (HttpClient client = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(5) })
{
return await client.GetAsync(uri);
}

View File

@ -107,7 +107,11 @@ namespace Microsoft.Net.Http.Server
private async Task<string> SendRequestAsync(string uri,
X509Certificate cert = null)
{
#if DNX451
WebRequestHandler handler = new WebRequestHandler();
#else
WinHttpHandler handler = new WinHttpHandler();
#endif
handler.ServerCertificateValidationCallback = (a, b, c, d) => true;
if (cert != null)
{
@ -121,7 +125,11 @@ namespace Microsoft.Net.Http.Server
private async Task<string> SendRequestAsync(string uri, string upload)
{
#if DNX451
WebRequestHandler handler = new WebRequestHandler();
#else
WinHttpHandler handler = new WinHttpHandler();
#endif
handler.ServerCertificateValidationCallback = (a, b, c, d) => true;
using (HttpClient client = new HttpClient(handler))
{

View File

@ -167,7 +167,7 @@ namespace Microsoft.Net.Http.Server
}
catch (Exception)
{
client.Close();
((IDisposable)client).Dispose();
throw;
}
}

View File

@ -352,7 +352,7 @@ namespace Microsoft.Net.Http.Server
}
catch (Exception)
{
client.Close();
((IDisposable)client).Dispose();
throw;
}
}

View File

@ -99,7 +99,7 @@ namespace Microsoft.Net.Http.Server
byte[] response = new byte[1024 * 5];
await Task.Run(() => socket.Receive(response));
socket.Close();
socket.Dispose();
}
}
}

View File

@ -8,6 +8,7 @@ using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Testing.xunit;
using Xunit;
namespace Microsoft.Net.Http.Server
@ -94,7 +95,7 @@ namespace Microsoft.Net.Http.Server
Task<HttpResponseMessage> responseTask = SendRequestAsync(address);
var context = await server.GetContextAsync();
context.Response.Headers["transfeR-Encoding"] = " CHunked ";
context.Response.Headers["transfeR-Encoding"] = "CHunked";
Stream stream = context.Response.Body;
var responseBytes = Encoding.ASCII.GetBytes("10\r\nManually Chunked\r\n0\r\n\r\n");
await stream.WriteAsync(responseBytes, 0, responseBytes.Length);
@ -121,7 +122,11 @@ namespace Microsoft.Net.Http.Server
var context = await server.GetContextAsync();
context.Response.Headers["Content-lenGth"] = " 30 ";
Stream stream = context.Response.Body;
#if DNX451
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);
await stream.WriteAsync(new byte[10], 0, 10);
context.Dispose();
@ -148,12 +153,12 @@ namespace Microsoft.Net.Http.Server
var context = await server.GetContextAsync();
context.Response.Headers["Content-lenGth"] = " 20 ";
context.Dispose();
#if !DNXCORE50
// HttpClient retries the request because it didn't get a response.
context = await server.GetContextAsync();
context.Response.Headers["Content-lenGth"] = " 20 ";
context.Dispose();
#endif
await Assert.ThrowsAsync<HttpRequestException>(() => responseTask);
}
}
@ -170,13 +175,13 @@ namespace Microsoft.Net.Http.Server
context.Response.Headers["Content-lenGth"] = " 20 ";
context.Response.Body.Write(new byte[5], 0, 5);
context.Dispose();
#if !DNXCORE50
// HttpClient retries the request because it didn't get a response.
context = await server.GetContextAsync();
context.Response.Headers["Content-lenGth"] = " 20 ";
context.Response.Body.Write(new byte[5], 0, 5);
context.Dispose();
#endif
await Assert.ThrowsAsync<HttpRequestException>(() => responseTask);
}
}
@ -194,14 +199,14 @@ namespace Microsoft.Net.Http.Server
context.Response.Body.Write(new byte[5], 0, 5);
Assert.Throws<InvalidOperationException>(() => context.Response.Body.Write(new byte[6], 0, 6));
context.Dispose();
#if !DNXCORE50
// HttpClient retries the request because it didn't get a response.
context = await server.GetContextAsync();
context.Response.Headers["Content-lenGth"] = " 10 ";
context.Response.Body.Write(new byte[5], 0, 5);
Assert.Throws<InvalidOperationException>(() => context.Response.Body.Write(new byte[6], 0, 6));
context.Dispose();
#endif
await Assert.ThrowsAsync<HttpRequestException>(() => responseTask);
}
}

View File

@ -6,9 +6,10 @@ using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Testing.xunit;
using Xunit;
namespace Microsoft.Net.Http.Server.FunctionalTests
namespace Microsoft.Net.Http.Server
{
public class ResponseCachingTests
{
@ -17,7 +18,7 @@ namespace Microsoft.Net.Http.Server.FunctionalTests
public ResponseCachingTests()
{
_absoluteFilePath = Directory.GetFiles(Environment.CurrentDirectory).First();
_absoluteFilePath = Directory.GetFiles(Directory.GetCurrentDirectory()).First();
_fileLength = new FileInfo(_absoluteFilePath).Length;
}
@ -473,6 +474,12 @@ namespace Microsoft.Net.Http.Server.FunctionalTests
// Http.Sys will cache any status code.
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 context = await server.GetContextAsync();
@ -935,7 +942,8 @@ namespace Microsoft.Net.Http.Server.FunctionalTests
}
// 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()
{
string address;
@ -956,11 +964,11 @@ namespace Microsoft.Net.Http.Server.FunctionalTests
Assert.Equal("1", response.Headers.GetValues("x-request-count").FirstOrDefault());
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("1", response.Headers.GetValues("x-request-count").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()
{
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).
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("1", response.Headers.GetValues("x-request-count").FirstOrDefault());
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("1", response.Headers.GetValues("x-request-count").FirstOrDefault());
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).
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("1", response.Headers.GetValues("x-request-count").FirstOrDefault());
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);
if (!string.IsNullOrEmpty(extraHeader))
using (var client = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(5) })
{
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);
}
}
}

View File

@ -192,7 +192,7 @@ namespace Microsoft.Net.Http.Server
Assert.Equal(0, response.ContentLength);
Assert.NotNull(response.Headers["Date"]);
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.NotNull(response.Headers["Date"]);
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"));
#endif
}
}
@ -242,7 +246,11 @@ namespace Microsoft.Net.Http.Server
Assert.Equal(0, response.ContentLength);
Assert.NotNull(response.Headers["Date"]);
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"));
#endif
}
}

View File

@ -19,7 +19,7 @@ namespace Microsoft.Net.Http.Server
public ResponseSendFileTests()
{
AbsoluteFilePath = Directory.GetFiles(Environment.CurrentDirectory).First();
AbsoluteFilePath = Directory.GetFiles(Directory.GetCurrentDirectory()).First();
RelativeFilePath = Path.GetFileName(AbsoluteFilePath);
FileLength = new FileInfo(AbsoluteFilePath).Length;
}
@ -205,9 +205,9 @@ namespace Microsoft.Net.Http.Server
[Fact]
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);
emptyFile.Close();
emptyFile.Dispose();
string address;
using (var server = Utilities.CreateHttpServer(out address))

View File

@ -8,6 +8,7 @@ using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Testing.xunit;
using Xunit;
namespace Microsoft.Net.Http.Server
@ -122,11 +123,11 @@ namespace Microsoft.Net.Http.Server
context.Abort();
Assert.True(canceled.WaitOne(interval), "Aborted");
Assert.True(ct.IsCancellationRequested, "IsCancellationRequested");
#if !DNXCORE50
// HttpClient re-tries the request because it doesn't know if the request was received.
context = await server.GetContextAsync();
context.Abort();
#endif
await Assert.ThrowsAsync<HttpRequestException>(() => responseTask);
}
}
@ -246,7 +247,6 @@ namespace Microsoft.Net.Http.Server
private async Task<string> SendRequestAsync(string uri)
{
ServicePointManager.DefaultConnectionLimit = 100;
using (HttpClient client = new HttpClient())
{
return await client.GetStringAsync(uri);

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.DirectoryServices.ActiveDirectory;
using Microsoft.AspNet.Testing.xunit;
namespace Microsoft.Net.Http.Server
@ -19,7 +18,9 @@ namespace Microsoft.Net.Http.Server
{
try
{
return !string.IsNullOrEmpty(Domain.GetComputerDomain().Name);
#if DNX451
return !string.IsNullOrEmpty(System.DirectoryServices.ActiveDirectory.Domain.GetComputerDomain().Name);
#endif
}
catch
{

View File

@ -15,6 +15,14 @@
"System.Net.Http": "",
"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-*"
}
}
}
}