From af6a17710b4e7f0b0165e4beb02d61cbad6e9da2 Mon Sep 17 00:00:00 2001 From: Chris R Date: Tue, 16 Jun 2015 16:26:37 -0700 Subject: [PATCH] #310 Refactor IRequestIdentifierFeature. --- ...re.cs => IHttpRequestIdentifierFeature.cs} | 4 ++-- .../Features/HttpRequestIdentifierFeature.cs | 10 ++++++++++ src/Microsoft.AspNet.Owin/OwinEnvironment.cs | 9 ++++++--- .../OwinFeatureCollection.cs | 20 +++++-------------- 4 files changed, 23 insertions(+), 20 deletions(-) rename src/Microsoft.AspNet.Http.Features/{IRequestIdentifierFeature.cs => IHttpRequestIdentifierFeature.cs} (80%) create mode 100644 src/Microsoft.AspNet.Http/Features/HttpRequestIdentifierFeature.cs diff --git a/src/Microsoft.AspNet.Http.Features/IRequestIdentifierFeature.cs b/src/Microsoft.AspNet.Http.Features/IHttpRequestIdentifierFeature.cs similarity index 80% rename from src/Microsoft.AspNet.Http.Features/IRequestIdentifierFeature.cs rename to src/Microsoft.AspNet.Http.Features/IHttpRequestIdentifierFeature.cs index b34afe8f96..163988d832 100644 --- a/src/Microsoft.AspNet.Http.Features/IRequestIdentifierFeature.cs +++ b/src/Microsoft.AspNet.Http.Features/IHttpRequestIdentifierFeature.cs @@ -8,11 +8,11 @@ namespace Microsoft.AspNet.Http.Features /// /// Feature to identify a request. /// - public interface IRequestIdentifierFeature + public interface IHttpRequestIdentifierFeature { /// /// Identifier to trace a request. /// - Guid TraceIdentifier { get; } + string TraceIdentifier { get; set; } } } diff --git a/src/Microsoft.AspNet.Http/Features/HttpRequestIdentifierFeature.cs b/src/Microsoft.AspNet.Http/Features/HttpRequestIdentifierFeature.cs new file mode 100644 index 0000000000..01dd9d0ee5 --- /dev/null +++ b/src/Microsoft.AspNet.Http/Features/HttpRequestIdentifierFeature.cs @@ -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; } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Owin/OwinEnvironment.cs b/src/Microsoft.AspNet.Owin/OwinEnvironment.cs index 0f5237ffbd..5d1f95119c 100644 --- a/src/Microsoft.AspNet.Owin/OwinEnvironment.cs +++ b/src/Microsoft.AspNet.Owin/OwinEnvironment.cs @@ -15,6 +15,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; +using Microsoft.AspNet.Http.Features.Internal; using Microsoft.AspNet.Http.Features.Authentication; using Microsoft.AspNet.Http.Features.Authentication.Internal; @@ -80,6 +81,11 @@ namespace Microsoft.AspNet.Owin { OwinConstants.Security.User, new FeatureMap(feature => feature.User, ()=> null, (feature, value) => feature.User = Utilities.MakeClaimsPrincipal((IPrincipal)value), () => new HttpAuthenticationFeature()) + }, + + { OwinConstants.RequestId, new FeatureMap(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 - - // The request identifier is a string per the spec. - _entries[OwinConstants.RequestId] = new FeatureMap(feature => feature.TraceIdentifier.ToString()); } // Public in case there's a new/custom feature interface that needs to be added. diff --git a/src/Microsoft.AspNet.Owin/OwinFeatureCollection.cs b/src/Microsoft.AspNet.Owin/OwinFeatureCollection.cs index c4030d9ed6..b7e6598383 100644 --- a/src/Microsoft.AspNet.Owin/OwinFeatureCollection.cs +++ b/src/Microsoft.AspNet.Owin/OwinFeatureCollection.cs @@ -30,11 +30,11 @@ namespace Microsoft.AspNet.Owin IHttpConnectionFeature, IHttpSendFileFeature, ITlsConnectionFeature, + IHttpRequestIdentifierFeature, IHttpRequestLifetimeFeature, IHttpAuthenticationFeature, IHttpWebSocketFeature, - IOwinEnvironmentFeature, - IRequestIdentifierFeature + IOwinEnvironmentFeature { public IDictionary Environment { get; set; } private bool _headersSent; @@ -435,20 +435,10 @@ namespace Microsoft.AspNet.Owin get { return true; } } - Guid IRequestIdentifierFeature.TraceIdentifier + string IHttpRequestIdentifierFeature.TraceIdentifier { - get - { - var requestId = Prop(OwinConstants.RequestId); - Guid requestIdentifier; - - if (requestId != null && Guid.TryParse(requestId, out requestIdentifier)) - { - return requestIdentifier; - } - - return Guid.Empty; - } + get { return Prop(OwinConstants.RequestId); } + set { Prop(OwinConstants.RequestId, value); } } public bool Remove(KeyValuePair item)