#310 Refactor IRequestIdentifierFeature.

This commit is contained in:
Chris R 2015-06-16 16:26:37 -07:00
parent a79b05bf24
commit af6a17710b
4 changed files with 23 additions and 20 deletions

View File

@ -8,11 +8,11 @@ namespace Microsoft.AspNet.Http.Features
/// <summary> /// <summary>
/// Feature to identify a request. /// Feature to identify a request.
/// </summary> /// </summary>
public interface IRequestIdentifierFeature public interface IHttpRequestIdentifierFeature
{ {
/// <summary> /// <summary>
/// Identifier to trace a request. /// Identifier to trace a request.
/// </summary> /// </summary>
Guid TraceIdentifier { get; } string TraceIdentifier { get; set; }
} }
} }

View File

@ -0,0 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNet.Http.Features.Internal
{
public class HttpRequestIdentifierFeature : IHttpRequestIdentifierFeature
{
public string TraceIdentifier { get; set; }
}
}

View File

@ -15,6 +15,7 @@ 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.Features.Internal;
using Microsoft.AspNet.Http.Features.Authentication; using Microsoft.AspNet.Http.Features.Authentication;
using Microsoft.AspNet.Http.Features.Authentication.Internal; using Microsoft.AspNet.Http.Features.Authentication.Internal;
@ -80,6 +81,11 @@ namespace Microsoft.AspNet.Owin
{ OwinConstants.Security.User, new FeatureMap<IHttpAuthenticationFeature>(feature => feature.User, { OwinConstants.Security.User, new FeatureMap<IHttpAuthenticationFeature>(feature => feature.User,
()=> null, (feature, value) => feature.User = Utilities.MakeClaimsPrincipal((IPrincipal)value), ()=> null, (feature, value) => feature.User = Utilities.MakeClaimsPrincipal((IPrincipal)value),
() => new HttpAuthenticationFeature()) () => new HttpAuthenticationFeature())
},
{ OwinConstants.RequestId, new FeatureMap<IHttpRequestIdentifierFeature>(feature => feature.TraceIdentifier,
()=> null, (feature, value) => feature.TraceIdentifier = (string)value,
() => new HttpRequestIdentifierFeature())
} }
}; };
@ -113,9 +119,6 @@ namespace Microsoft.AspNet.Owin
} }
_context.Items[typeof(HttpContext).FullName] = _context; // Store for lookup when we transition back out of OWIN _context.Items[typeof(HttpContext).FullName] = _context; // Store for lookup when we transition back out of OWIN
// The request identifier is a string per the spec.
_entries[OwinConstants.RequestId] = new FeatureMap<IRequestIdentifierFeature>(feature => feature.TraceIdentifier.ToString());
} }
// Public in case there's a new/custom feature interface that needs to be added. // Public in case there's a new/custom feature interface that needs to be added.

View File

@ -30,11 +30,11 @@ namespace Microsoft.AspNet.Owin
IHttpConnectionFeature, IHttpConnectionFeature,
IHttpSendFileFeature, IHttpSendFileFeature,
ITlsConnectionFeature, ITlsConnectionFeature,
IHttpRequestIdentifierFeature,
IHttpRequestLifetimeFeature, IHttpRequestLifetimeFeature,
IHttpAuthenticationFeature, IHttpAuthenticationFeature,
IHttpWebSocketFeature, IHttpWebSocketFeature,
IOwinEnvironmentFeature, IOwinEnvironmentFeature
IRequestIdentifierFeature
{ {
public IDictionary<string, object> Environment { get; set; } public IDictionary<string, object> Environment { get; set; }
private bool _headersSent; private bool _headersSent;
@ -435,20 +435,10 @@ namespace Microsoft.AspNet.Owin
get { return true; } get { return true; }
} }
Guid IRequestIdentifierFeature.TraceIdentifier string IHttpRequestIdentifierFeature.TraceIdentifier
{ {
get get { return Prop<string>(OwinConstants.RequestId); }
{ set { Prop(OwinConstants.RequestId, value); }
var requestId = Prop<string>(OwinConstants.RequestId);
Guid requestIdentifier;
if (requestId != null && Guid.TryParse(requestId, out requestIdentifier))
{
return requestIdentifier;
}
return Guid.Empty;
}
} }
public bool Remove(KeyValuePair<Type, object> item) public bool Remove(KeyValuePair<Type, object> item)