#149 - Expose connection information as 1st class.
This commit is contained in:
parent
c69c289abf
commit
22a1cab976
|
|
@ -0,0 +1,76 @@
|
|||
// 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.Net;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.FeatureModel;
|
||||
using Microsoft.AspNet.Http.Core.Infrastructure;
|
||||
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public class DefaultConnectionInfo : ConnectionInfo
|
||||
{
|
||||
private readonly IFeatureCollection _features;
|
||||
|
||||
private FeatureReference<IHttpConnectionFeature> _connection = FeatureReference<IHttpConnectionFeature>.Default;
|
||||
private FeatureReference<IHttpClientCertificateFeature> _clientCertificate = FeatureReference<IHttpClientCertificateFeature>.Default;
|
||||
|
||||
public DefaultConnectionInfo(IFeatureCollection features)
|
||||
{
|
||||
_features = features;
|
||||
}
|
||||
|
||||
private IHttpConnectionFeature HttpConnectionFeature
|
||||
{
|
||||
get { return _connection.Fetch(_features) ?? _connection.Update(_features, new HttpConnectionFeature()); }
|
||||
}
|
||||
|
||||
private IHttpClientCertificateFeature HttpClientCertificateFeature
|
||||
{
|
||||
get { return _clientCertificate.Fetch(_features) ?? _clientCertificate.Update(_features, new HttpClientCertificateFeature()); }
|
||||
}
|
||||
|
||||
public override IPAddress RemoteIpAddress
|
||||
{
|
||||
get { return HttpConnectionFeature.RemoteIpAddress; }
|
||||
set { HttpConnectionFeature.RemoteIpAddress = value; }
|
||||
}
|
||||
|
||||
public override int RemotePort
|
||||
{
|
||||
get { return HttpConnectionFeature.RemotePort; }
|
||||
set { HttpConnectionFeature.RemotePort = value; }
|
||||
}
|
||||
|
||||
public override IPAddress LocalIpAddress
|
||||
{
|
||||
get { return HttpConnectionFeature.LocalIpAddress; }
|
||||
set { HttpConnectionFeature.LocalIpAddress = value; }
|
||||
}
|
||||
|
||||
public override int LocalPort
|
||||
{
|
||||
get { return HttpConnectionFeature.LocalPort; }
|
||||
set { HttpConnectionFeature.LocalPort = value; }
|
||||
}
|
||||
|
||||
public override bool IsLocal
|
||||
{
|
||||
get { return HttpConnectionFeature.IsLocal; }
|
||||
set { HttpConnectionFeature.IsLocal = value; }
|
||||
}
|
||||
|
||||
public override X509Certificate ClientCertificate
|
||||
{
|
||||
get { return HttpClientCertificateFeature.ClientCertificate; }
|
||||
set { HttpClientCertificateFeature.ClientCertificate = value; }
|
||||
}
|
||||
|
||||
public override Task<X509Certificate> GetClientCertificateAsync(CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
return HttpClientCertificateFeature.GetClientCertificateAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +23,7 @@ namespace Microsoft.AspNet.Http.Core
|
|||
|
||||
private readonly HttpRequest _request;
|
||||
private readonly HttpResponse _response;
|
||||
private readonly ConnectionInfo _connection;
|
||||
|
||||
private FeatureReference<IItemsFeature> _items;
|
||||
private FeatureReference<IServiceProvidersFeature> _serviceProviders;
|
||||
|
|
@ -44,6 +45,7 @@ namespace Microsoft.AspNet.Http.Core
|
|||
_features = features;
|
||||
_request = new DefaultHttpRequest(this, features);
|
||||
_response = new DefaultHttpResponse(this, features);
|
||||
_connection = new DefaultConnectionInfo(features);
|
||||
|
||||
_items = FeatureReference<IItemsFeature>.Default;
|
||||
_serviceProviders = FeatureReference<IServiceProvidersFeature>.Default;
|
||||
|
|
@ -87,6 +89,8 @@ namespace Microsoft.AspNet.Http.Core
|
|||
|
||||
public override HttpResponse Response { get { return _response; } }
|
||||
|
||||
public override ConnectionInfo Connection { get { return _connection; } }
|
||||
|
||||
public override ClaimsPrincipal User
|
||||
{
|
||||
get
|
||||
|
|
|
|||
|
|
@ -19,8 +19,6 @@ namespace Microsoft.AspNet.Http.Core
|
|||
private readonly IFeatureCollection _features;
|
||||
|
||||
private FeatureReference<IHttpRequestFeature> _request = FeatureReference<IHttpRequestFeature>.Default;
|
||||
private FeatureReference<IHttpConnectionFeature> _connection = FeatureReference<IHttpConnectionFeature>.Default;
|
||||
private FeatureReference<IHttpClientCertificateFeature> _clientCertificate = FeatureReference<IHttpClientCertificateFeature>.Default;
|
||||
private FeatureReference<IQueryFeature> _query = FeatureReference<IQueryFeature>.Default;
|
||||
private FeatureReference<IFormFeature> _form = FeatureReference<IFormFeature>.Default;
|
||||
private FeatureReference<IRequestCookiesFeature> _cookies = FeatureReference<IRequestCookiesFeature>.Default;
|
||||
|
|
@ -36,16 +34,6 @@ namespace Microsoft.AspNet.Http.Core
|
|||
get { return _request.Fetch(_features); }
|
||||
}
|
||||
|
||||
private IHttpConnectionFeature HttpConnectionFeature
|
||||
{
|
||||
get { return _connection.Fetch(_features); }
|
||||
}
|
||||
|
||||
private IHttpClientCertificateFeature HttpClientCertificateFeature
|
||||
{
|
||||
get { return _clientCertificate.Fetch(_features); }
|
||||
}
|
||||
|
||||
private IQueryFeature QueryFeature
|
||||
{
|
||||
get { return _query.Fetch(_features) ?? _query.Update(_features, new QueryFeature(_features)); }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
// 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.Security.Cryptography.X509Certificates;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public class HttpClientCertificateFeature : IHttpClientCertificateFeature
|
||||
{
|
||||
public HttpClientCertificateFeature()
|
||||
{
|
||||
}
|
||||
|
||||
public X509Certificate ClientCertificate { get; set; }
|
||||
|
||||
public Task<X509Certificate> GetClientCertificateAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.FromResult(ClientCertificate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
// 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.Net;
|
||||
|
||||
namespace Microsoft.AspNet.Http.Core
|
||||
{
|
||||
public class HttpConnectionFeature : IHttpConnectionFeature
|
||||
{
|
||||
public HttpConnectionFeature()
|
||||
{
|
||||
}
|
||||
|
||||
public bool IsLocal { get; set; }
|
||||
|
||||
public IPAddress LocalIpAddress { get; set; }
|
||||
|
||||
public int LocalPort { get; set; }
|
||||
|
||||
public IPAddress RemoteIpAddress { get; set; }
|
||||
|
||||
public int RemotePort { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,6 @@
|
|||
"Microsoft.AspNet.Http.Interfaces": "1.0.0-*",
|
||||
"Microsoft.AspNet.WebUtilities": "1.0.0-*",
|
||||
"Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" },
|
||||
"Microsoft.Framework.WebEncoders.Core": "1.0.0-*",
|
||||
"Microsoft.Net.Http.Headers": "1.0.0-*"
|
||||
},
|
||||
"frameworks": {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
// 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.Net;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.AspNet.Http
|
||||
{
|
||||
public abstract class ConnectionInfo
|
||||
{
|
||||
public abstract IPAddress RemoteIpAddress { get; set; }
|
||||
|
||||
public abstract int RemotePort { get; set; }
|
||||
|
||||
public abstract IPAddress LocalIpAddress { get; set; }
|
||||
|
||||
public abstract int LocalPort { get; set; }
|
||||
|
||||
public abstract bool IsLocal { get; set; }
|
||||
|
||||
public abstract X509Certificate ClientCertificate { get; set; }
|
||||
|
||||
public abstract Task<X509Certificate> GetClientCertificateAsync(CancellationToken cancellationToken = new CancellationToken());
|
||||
}
|
||||
}
|
||||
|
|
@ -18,8 +18,10 @@ namespace Microsoft.AspNet.Http
|
|||
|
||||
public abstract HttpResponse Response { get; }
|
||||
|
||||
public abstract ConnectionInfo Connection { get; }
|
||||
|
||||
public abstract ClaimsPrincipal User { get; set; }
|
||||
|
||||
|
||||
public abstract IDictionary<object, object> Items { get; }
|
||||
|
||||
public abstract IServiceProvider ApplicationServices { get; set; }
|
||||
|
|
|
|||
|
|
@ -14,10 +14,12 @@
|
|||
"System.Globalization": "4.0.10-beta-*",
|
||||
"System.Globalization.Extensions": "4.0.0-beta-*",
|
||||
"System.Linq": "4.0.0-beta-*",
|
||||
"System.Net.Primitives": "4.0.10-beta-*",
|
||||
"System.Net.WebSockets" : "4.0.0-beta-*",
|
||||
"System.Runtime": "4.0.20-beta-*",
|
||||
"System.Runtime.InteropServices": "4.0.20-beta-*",
|
||||
"System.Security.Claims": "4.0.0-beta-*",
|
||||
"System.Security.Cryptography.X509Certificates": "4.0.0-beta-*",
|
||||
"System.Security.Principal": "4.0.0-beta-*",
|
||||
"System.Threading.Tasks": "4.0.10-beta-*"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue