#91 Provide a default constructor for DefaultHttpContext.
This commit is contained in:
parent
9028c6a1a5
commit
5bf4883cd9
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
// Copyright (c) Microsoft Open Technologies, Inc. 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.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
@ -6,10 +6,22 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.AspNet.HttpFeature;
|
using Microsoft.AspNet.HttpFeature;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Builder.Extensions
|
namespace Microsoft.AspNet.PipelineCore
|
||||||
{
|
{
|
||||||
public class FakeHttpRequestFeature : IHttpRequestFeature
|
public class DeafultHttpRequestFeature : IHttpRequestFeature
|
||||||
{
|
{
|
||||||
|
public DeafultHttpRequestFeature()
|
||||||
|
{
|
||||||
|
Headers = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
Body = Stream.Null;
|
||||||
|
Protocol = string.Empty;
|
||||||
|
Scheme = string.Empty;
|
||||||
|
Method = string.Empty;
|
||||||
|
PathBase = string.Empty;
|
||||||
|
Path = string.Empty;
|
||||||
|
QueryString = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
public string Protocol { get; set; }
|
public string Protocol { get; set; }
|
||||||
public string Scheme { get; set; }
|
public string Scheme { get; set; }
|
||||||
public string Method { get; set; }
|
public string Method { get; set; }
|
||||||
|
|
@ -19,16 +31,4 @@ namespace Microsoft.AspNet.Builder.Extensions
|
||||||
public IDictionary<string, string[]> Headers { get; set; }
|
public IDictionary<string, string[]> Headers { get; set; }
|
||||||
public Stream Body { get; set; }
|
public Stream Body { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FakeHttpResponseFeature : IHttpResponseFeature
|
|
||||||
{
|
|
||||||
public int StatusCode { get; set; }
|
|
||||||
public string ReasonPhrase { get; set; }
|
|
||||||
public IDictionary<string, string[]> Headers { get; set; }
|
|
||||||
public Stream Body { get; set; }
|
|
||||||
public void OnSendingHeaders(Action<object> callback, object state)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -33,6 +33,13 @@ namespace Microsoft.AspNet.PipelineCore
|
||||||
private FeatureReference<IHttpWebSocketFeature> _webSockets;
|
private FeatureReference<IHttpWebSocketFeature> _webSockets;
|
||||||
private IFeatureCollection _features;
|
private IFeatureCollection _features;
|
||||||
|
|
||||||
|
public DefaultHttpContext()
|
||||||
|
: this(new FeatureCollection())
|
||||||
|
{
|
||||||
|
SetFeature<IHttpRequestFeature>(new DeafultHttpRequestFeature());
|
||||||
|
SetFeature<IHttpResponseFeature>(new DefaultHttpResponseFeature());
|
||||||
|
}
|
||||||
|
|
||||||
public DefaultHttpContext(IFeatureCollection features)
|
public DefaultHttpContext(IFeatureCollection features)
|
||||||
{
|
{
|
||||||
_features = features;
|
_features = features;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using Microsoft.AspNet.HttpFeature;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.PipelineCore
|
||||||
|
{
|
||||||
|
public class DefaultHttpResponseFeature : IHttpResponseFeature
|
||||||
|
{
|
||||||
|
public DefaultHttpResponseFeature()
|
||||||
|
{
|
||||||
|
StatusCode = 200;
|
||||||
|
Headers = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
Body = Stream.Null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int StatusCode { get; set; }
|
||||||
|
|
||||||
|
public string ReasonPhrase { get; set; }
|
||||||
|
|
||||||
|
public IDictionary<string, string[]> Headers { get; set; }
|
||||||
|
|
||||||
|
public Stream Body { get; set; }
|
||||||
|
|
||||||
|
public void OnSendingHeaders(Action<object> callback, object state)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -27,6 +27,8 @@
|
||||||
<Compile Include="Collections\ReadableStringCollection.cs" />
|
<Compile Include="Collections\ReadableStringCollection.cs" />
|
||||||
<Compile Include="Collections\RequestCookiesCollection.cs" />
|
<Compile Include="Collections\RequestCookiesCollection.cs" />
|
||||||
<Compile Include="Collections\ResponseCookies.cs" />
|
<Compile Include="Collections\ResponseCookies.cs" />
|
||||||
|
<Compile Include="DeafultHttpRequestFeature.cs" />
|
||||||
|
<Compile Include="DefaultHttpResponseFeature.cs" />
|
||||||
<Compile Include="FormFeature.cs" />
|
<Compile Include="FormFeature.cs" />
|
||||||
<Compile Include="ItemsFeature.cs" />
|
<Compile Include="ItemsFeature.cs" />
|
||||||
<Compile Include="QueryFeature.cs" />
|
<Compile Include="QueryFeature.cs" />
|
||||||
|
|
|
||||||
|
|
@ -187,9 +187,7 @@ namespace Microsoft.AspNet.Builder.Extensions
|
||||||
|
|
||||||
private HttpContext CreateRequest(string basePath, string requestPath)
|
private HttpContext CreateRequest(string basePath, string requestPath)
|
||||||
{
|
{
|
||||||
HttpContext context = new DefaultHttpContext(new FeatureModel.FeatureCollection());
|
HttpContext context = new DefaultHttpContext();
|
||||||
context.SetFeature<IHttpRequestFeature>(new FakeHttpRequestFeature());
|
|
||||||
context.SetFeature<IHttpResponseFeature>(new FakeHttpResponseFeature());
|
|
||||||
context.Request.PathBase = new PathString(basePath);
|
context.Request.PathBase = new PathString(basePath);
|
||||||
context.Request.Path = new PathString(requestPath);
|
context.Request.Path = new PathString(requestPath);
|
||||||
return context;
|
return context;
|
||||||
|
|
|
||||||
|
|
@ -176,9 +176,7 @@ namespace Microsoft.AspNet.Builder.Extensions
|
||||||
|
|
||||||
private HttpContext CreateRequest()
|
private HttpContext CreateRequest()
|
||||||
{
|
{
|
||||||
HttpContext context = new DefaultHttpContext(new FeatureModel.FeatureCollection());
|
HttpContext context = new DefaultHttpContext();
|
||||||
context.SetFeature<IHttpRequestFeature>(new FakeHttpRequestFeature());
|
|
||||||
context.SetFeature<IHttpResponseFeature>(new FakeHttpResponseFeature());
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,9 @@
|
||||||
<Content Include="project.json" />
|
<Content Include="project.json" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Fakes.cs" />
|
|
||||||
<Compile Include="MapPathMiddlewareTests.cs" />
|
<Compile Include="MapPathMiddlewareTests.cs" />
|
||||||
<Compile Include="MapPredicateMiddlewareTests.cs" />
|
<Compile Include="MapPredicateMiddlewareTests.cs" />
|
||||||
<Compile Include="PathStringTests.cs" />
|
<Compile Include="PathStringTests.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -1,16 +1,11 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
// Copyright (c) Microsoft Open Technologies, Inc. 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.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Threading;
|
|
||||||
using Microsoft.AspNet.FeatureModel;
|
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.HttpFeature;
|
|
||||||
using Microsoft.AspNet.HttpFeature.Security;
|
|
||||||
using Microsoft.AspNet.PipelineCore;
|
using Microsoft.AspNet.PipelineCore;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
@ -101,66 +96,8 @@ namespace Microsoft.AspNet.Owin
|
||||||
|
|
||||||
private HttpContext CreateContext()
|
private HttpContext CreateContext()
|
||||||
{
|
{
|
||||||
var features = new FeatureCollection();
|
var context = new DefaultHttpContext();
|
||||||
features.Add(typeof(IHttpRequestFeature), new MoqHttpRequestFeature());
|
return context;
|
||||||
features.Add(typeof(IHttpResponseFeature), new MoqHttpResponseFeature());
|
|
||||||
features.Add(typeof(IHttpRequestLifetimeFeature), new MoqHttpRequestLifetimeFeature());
|
|
||||||
return new DefaultHttpContext(features);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class MoqHttpRequestFeature : IHttpRequestFeature
|
|
||||||
{
|
|
||||||
public MoqHttpRequestFeature()
|
|
||||||
{
|
|
||||||
Headers = new Dictionary<string, string[]>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Method { get; set; }
|
|
||||||
|
|
||||||
public string Scheme { get; set; }
|
|
||||||
|
|
||||||
public string Protocol { get; set; }
|
|
||||||
|
|
||||||
public Stream Body { get; set; }
|
|
||||||
|
|
||||||
public string PathBase { get; set; }
|
|
||||||
|
|
||||||
public string Path { get; set; }
|
|
||||||
|
|
||||||
public string QueryString { get; set; }
|
|
||||||
|
|
||||||
public IDictionary<string, string[]> Headers { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private class MoqHttpResponseFeature : IHttpResponseFeature
|
|
||||||
{
|
|
||||||
public MoqHttpResponseFeature()
|
|
||||||
{
|
|
||||||
Headers = new Dictionary<string, string[]>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Stream Body { get; set; }
|
|
||||||
|
|
||||||
public int StatusCode { get; set; }
|
|
||||||
|
|
||||||
public string ReasonPhrase { get; set; }
|
|
||||||
|
|
||||||
public IDictionary<string, string[]> Headers { get; set; }
|
|
||||||
|
|
||||||
public void OnSendingHeaders(Action<object> callback, object state)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class MoqHttpRequestLifetimeFeature : IHttpRequestLifetimeFeature
|
|
||||||
{
|
|
||||||
public CancellationToken RequestAborted { get; private set; }
|
|
||||||
|
|
||||||
public void Abort()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,25 +80,8 @@ namespace Microsoft.AspNet.PipelineCore.Tests
|
||||||
|
|
||||||
private HttpContext CreateContext()
|
private HttpContext CreateContext()
|
||||||
{
|
{
|
||||||
var context = new DefaultHttpContext(new FeatureCollection());
|
var context = new DefaultHttpContext();
|
||||||
context.SetFeature<IHttpResponseFeature>(new FakeHttpResponse());
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class FakeHttpResponse : IHttpResponseFeature
|
|
||||||
{
|
|
||||||
public int StatusCode { get; set; }
|
|
||||||
|
|
||||||
public string ReasonPhrase { get; set; }
|
|
||||||
|
|
||||||
public IDictionary<string, string[]> Headers { get; set; }
|
|
||||||
|
|
||||||
public Stream Body { get; set; }
|
|
||||||
|
|
||||||
public void OnSendingHeaders(Action<object> callback, object state)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -5,9 +5,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.FeatureModel;
|
|
||||||
using Microsoft.AspNet.HttpFeature;
|
using Microsoft.AspNet.HttpFeature;
|
||||||
using Moq;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.PipelineCore.Tests
|
namespace Microsoft.AspNet.PipelineCore.Tests
|
||||||
|
|
@ -57,9 +55,9 @@ namespace Microsoft.AspNet.PipelineCore.Tests
|
||||||
// Arrange
|
// Arrange
|
||||||
const string expected = "localhost:9001";
|
const string expected = "localhost:9001";
|
||||||
|
|
||||||
var headers = new Dictionary<string, string[]>(StringComparer.Ordinal)
|
var headers = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase)
|
||||||
{
|
{
|
||||||
{ "Host", new string[]{ expected } },
|
{ "Host", new string[] { expected } },
|
||||||
};
|
};
|
||||||
|
|
||||||
var request = CreateRequest(headers);
|
var request = CreateRequest(headers);
|
||||||
|
|
@ -77,7 +75,7 @@ namespace Microsoft.AspNet.PipelineCore.Tests
|
||||||
// Arrange
|
// Arrange
|
||||||
const string expected = "löcalhöst";
|
const string expected = "löcalhöst";
|
||||||
|
|
||||||
var headers = new Dictionary<string, string[]>(StringComparer.Ordinal)
|
var headers = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase)
|
||||||
{
|
{
|
||||||
{ "Host", new string[]{ "xn--lcalhst-90ae" } },
|
{ "Host", new string[]{ "xn--lcalhst-90ae" } },
|
||||||
};
|
};
|
||||||
|
|
@ -97,7 +95,7 @@ namespace Microsoft.AspNet.PipelineCore.Tests
|
||||||
// Arrange
|
// Arrange
|
||||||
const string expected = "xn--lcalhst-90ae";
|
const string expected = "xn--lcalhst-90ae";
|
||||||
|
|
||||||
var headers = new Dictionary<string, string[]>(StringComparer.Ordinal);
|
var headers = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
var request = CreateRequest(headers);
|
var request = CreateRequest(headers);
|
||||||
|
|
||||||
|
|
@ -108,25 +106,19 @@ namespace Microsoft.AspNet.PipelineCore.Tests
|
||||||
Assert.Equal(expected, headers["Host"][0]);
|
Assert.Equal(expected, headers["Host"][0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DefaultHttpRequest CreateRequest(IDictionary<string, string[]> headers)
|
private static HttpRequest CreateRequest(IDictionary<string, string[]> headers)
|
||||||
{
|
{
|
||||||
var requestInfo = new Mock<IHttpRequestFeature>();
|
var context = new DefaultHttpContext();
|
||||||
requestInfo.SetupGet(r => r.Headers).Returns(headers);
|
context.GetFeature<IHttpRequestFeature>().Headers = headers;
|
||||||
|
return context.Request;
|
||||||
var features = new FeatureCollection();
|
|
||||||
features.Add(typeof(IHttpRequestFeature), requestInfo.Object);
|
|
||||||
|
|
||||||
var context = new DefaultHttpContext(features);
|
|
||||||
return new DefaultHttpRequest(context, features);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DefaultHttpRequest GetRequestWithContentLength(string contentLength = null)
|
private static HttpRequest GetRequestWithContentLength(string contentLength = null)
|
||||||
{
|
{
|
||||||
var headers = new Dictionary<string, string[]>(StringComparer.Ordinal);
|
var headers = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
|
||||||
if (contentLength != null)
|
if (contentLength != null)
|
||||||
{
|
{
|
||||||
headers.Add("Content-Length", new[] { contentLength });
|
headers.Add("Content-Length", new[] { contentLength });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return CreateRequest(headers);
|
return CreateRequest(headers);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue