Implementing IRequestIdentifierFeature
Using code from HttpListener codebase to generate trace ids just to be consistent with other code.
This commit is contained in:
parent
c08721c7b3
commit
ca3259f703
|
|
@ -22,7 +22,6 @@ using System.Net;
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Security.Principal;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.FeatureModel;
|
using Microsoft.AspNet.FeatureModel;
|
||||||
|
|
@ -42,7 +41,8 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
IHttpRequestLifetimeFeature,
|
IHttpRequestLifetimeFeature,
|
||||||
IHttpWebSocketFeature,
|
IHttpWebSocketFeature,
|
||||||
IHttpAuthenticationFeature,
|
IHttpAuthenticationFeature,
|
||||||
IHttpUpgradeFeature
|
IHttpUpgradeFeature,
|
||||||
|
IRequestIdentifierFeature
|
||||||
{
|
{
|
||||||
private RequestContext _requestContext;
|
private RequestContext _requestContext;
|
||||||
private FeatureCollection _features;
|
private FeatureCollection _features;
|
||||||
|
|
@ -110,6 +110,8 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
_features.Add(typeof(IHttpWebSocketFeature), this);
|
_features.Add(typeof(IHttpWebSocketFeature), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_features.Add(typeof(IRequestIdentifierFeature), this);
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
/*
|
/*
|
||||||
Server
|
Server
|
||||||
|
|
@ -432,5 +434,13 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
get { return _authHandler; }
|
get { return _authHandler; }
|
||||||
set { _authHandler = value; }
|
set { _authHandler = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Guid IRequestIdentifierFeature.TraceIdentifier
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _requestContext.TraceIdentifier;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,19 @@ namespace Microsoft.Net.Http.Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public unsafe Guid TraceIdentifier
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// This is the base GUID used by HTTP.SYS for generating the activity ID.
|
||||||
|
// HTTP.SYS overwrites the first 8 bytes of the base GUID with RequestId to generate ETW activity ID.
|
||||||
|
|
||||||
|
var guid = new Guid(0xffcb4c93, 0xa57f, 0x453c, 0xb6, 0x3f, 0x84, 0x71, 0xc, 0x79, 0x67, 0xbb);
|
||||||
|
*((ulong*)&guid) = Request.RequestId;
|
||||||
|
return guid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The authentication challengest that will be added to the response if the status code is 401.
|
/// The authentication challengest that will be added to the response if the status code is 401.
|
||||||
/// This must be a subset of the AuthenticationSchemes enabled on the server.
|
/// This must be a subset of the AuthenticationSchemes enabled on the server.
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,11 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
Assert.NotEqual(0, connectionInfo.LocalPort);
|
Assert.NotEqual(0, connectionInfo.LocalPort);
|
||||||
Assert.True(connectionInfo.IsLocal);
|
Assert.True(connectionInfo.IsLocal);
|
||||||
|
|
||||||
|
// Trace identifier
|
||||||
|
var requestIdentifierFeature = httpContext.GetFeature<IRequestIdentifierFeature>();
|
||||||
|
Assert.NotNull(requestIdentifierFeature);
|
||||||
|
Assert.NotNull(requestIdentifierFeature.TraceIdentifier);
|
||||||
|
|
||||||
// Note: Response keys are validated in the ResponseTests
|
// Note: Response keys are validated in the ResponseTests
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -95,12 +100,17 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
{
|
{
|
||||||
var requestInfo = httpContext.GetFeature<IHttpRequestFeature>();
|
var requestInfo = httpContext.GetFeature<IHttpRequestFeature>();
|
||||||
var connectionInfo = httpContext.GetFeature<IHttpConnectionFeature>();
|
var connectionInfo = httpContext.GetFeature<IHttpConnectionFeature>();
|
||||||
|
var requestIdentifierFeature = httpContext.GetFeature<IRequestIdentifierFeature>();
|
||||||
|
|
||||||
// Request Keys
|
// Request Keys
|
||||||
Assert.Equal("http", requestInfo.Scheme);
|
Assert.Equal("http", requestInfo.Scheme);
|
||||||
Assert.Equal(expectedPath, requestInfo.Path);
|
Assert.Equal(expectedPath, requestInfo.Path);
|
||||||
Assert.Equal(expectedPathBase, requestInfo.PathBase);
|
Assert.Equal(expectedPathBase, requestInfo.PathBase);
|
||||||
Assert.Equal(string.Empty, requestInfo.QueryString);
|
Assert.Equal(string.Empty, requestInfo.QueryString);
|
||||||
|
|
||||||
|
// Trace identifier
|
||||||
|
Assert.NotNull(requestIdentifierFeature);
|
||||||
|
Assert.NotNull(requestIdentifierFeature.TraceIdentifier);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -135,10 +145,15 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
{
|
{
|
||||||
var httpContext = new DefaultHttpContext((IFeatureCollection)env);
|
var httpContext = new DefaultHttpContext((IFeatureCollection)env);
|
||||||
var requestInfo = httpContext.GetFeature<IHttpRequestFeature>();
|
var requestInfo = httpContext.GetFeature<IHttpRequestFeature>();
|
||||||
|
var requestIdentifierFeature = httpContext.GetFeature<IRequestIdentifierFeature>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Assert.Equal(expectedPath, requestInfo.Path);
|
Assert.Equal(expectedPath, requestInfo.Path);
|
||||||
Assert.Equal(expectedPathBase, requestInfo.PathBase);
|
Assert.Equal(expectedPathBase, requestInfo.PathBase);
|
||||||
|
|
||||||
|
// Trace identifier
|
||||||
|
Assert.NotNull(requestIdentifierFeature);
|
||||||
|
Assert.NotNull(requestIdentifierFeature.TraceIdentifier);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue