Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit af6a177

Browse files
committed
#310 Refactor IRequestIdentifierFeature.
1 parent a79b05b commit af6a177

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

src/Microsoft.AspNet.Http.Features/IRequestIdentifierFeature.cs renamed to src/Microsoft.AspNet.Http.Features/IHttpRequestIdentifierFeature.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ namespace Microsoft.AspNet.Http.Features
88
/// <summary>
99
/// Feature to identify a request.
1010
/// </summary>
11-
public interface IRequestIdentifierFeature
11+
public interface IHttpRequestIdentifierFeature
1212
{
1313
/// <summary>
1414
/// Identifier to trace a request.
1515
/// </summary>
16-
Guid TraceIdentifier { get; }
16+
string TraceIdentifier { get; set; }
1717
}
1818
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
namespace Microsoft.AspNet.Http.Features.Internal
5+
{
6+
public class HttpRequestIdentifierFeature : IHttpRequestIdentifierFeature
7+
{
8+
public string TraceIdentifier { get; set; }
9+
}
10+
}

src/Microsoft.AspNet.Owin/OwinEnvironment.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System.Threading.Tasks;
1616
using Microsoft.AspNet.Http;
1717
using Microsoft.AspNet.Http.Features;
18+
using Microsoft.AspNet.Http.Features.Internal;
1819
using Microsoft.AspNet.Http.Features.Authentication;
1920
using Microsoft.AspNet.Http.Features.Authentication.Internal;
2021

@@ -80,6 +81,11 @@ public OwinEnvironment(HttpContext context)
8081
{ OwinConstants.Security.User, new FeatureMap<IHttpAuthenticationFeature>(feature => feature.User,
8182
()=> null, (feature, value) => feature.User = Utilities.MakeClaimsPrincipal((IPrincipal)value),
8283
() => new HttpAuthenticationFeature())
84+
},
85+
86+
{ OwinConstants.RequestId, new FeatureMap<IHttpRequestIdentifierFeature>(feature => feature.TraceIdentifier,
87+
()=> null, (feature, value) => feature.TraceIdentifier = (string)value,
88+
() => new HttpRequestIdentifierFeature())
8389
}
8490
};
8591

@@ -113,9 +119,6 @@ public OwinEnvironment(HttpContext context)
113119
}
114120

115121
_context.Items[typeof(HttpContext).FullName] = _context; // Store for lookup when we transition back out of OWIN
116-
117-
// The request identifier is a string per the spec.
118-
_entries[OwinConstants.RequestId] = new FeatureMap<IRequestIdentifierFeature>(feature => feature.TraceIdentifier.ToString());
119122
}
120123

121124
// Public in case there's a new/custom feature interface that needs to be added.

src/Microsoft.AspNet.Owin/OwinFeatureCollection.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public class OwinFeatureCollection :
3030
IHttpConnectionFeature,
3131
IHttpSendFileFeature,
3232
ITlsConnectionFeature,
33+
IHttpRequestIdentifierFeature,
3334
IHttpRequestLifetimeFeature,
3435
IHttpAuthenticationFeature,
3536
IHttpWebSocketFeature,
36-
IOwinEnvironmentFeature,
37-
IRequestIdentifierFeature
37+
IOwinEnvironmentFeature
3838
{
3939
public IDictionary<string, object> Environment { get; set; }
4040
private bool _headersSent;
@@ -435,20 +435,10 @@ public bool IsReadOnly
435435
get { return true; }
436436
}
437437

438-
Guid IRequestIdentifierFeature.TraceIdentifier
438+
string IHttpRequestIdentifierFeature.TraceIdentifier
439439
{
440-
get
441-
{
442-
var requestId = Prop<string>(OwinConstants.RequestId);
443-
Guid requestIdentifier;
444-
445-
if (requestId != null && Guid.TryParse(requestId, out requestIdentifier))
446-
{
447-
return requestIdentifier;
448-
}
449-
450-
return Guid.Empty;
451-
}
440+
get { return Prop<string>(OwinConstants.RequestId); }
441+
set { Prop(OwinConstants.RequestId, value); }
452442
}
453443

454444
public bool Remove(KeyValuePair<Type, object> item)

0 commit comments

Comments
 (0)