Skip to content
This repository was archived by the owner on Mar 19, 2019. It is now read-only.

Implementing IRequestIdentifierFeature #94

Merged
merged 1 commit into from
Mar 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/Microsoft.AspNet.Server.WebListener/FeatureContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using System.Net.WebSockets;
using System.Security.Claims;
using System.Security.Cryptography.X509Certificates;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.FeatureModel;
Expand All @@ -42,7 +41,8 @@ internal class FeatureContext :
IHttpRequestLifetimeFeature,
IHttpWebSocketFeature,
IHttpAuthenticationFeature,
IHttpUpgradeFeature
IHttpUpgradeFeature,
IRequestIdentifierFeature
{
private RequestContext _requestContext;
private FeatureCollection _features;
Expand Down Expand Up @@ -110,6 +110,8 @@ private void PopulateFeatures()
_features.Add(typeof(IHttpWebSocketFeature), this);
}

_features.Add(typeof(IRequestIdentifierFeature), this);

// TODO:
/*
Server
Expand Down Expand Up @@ -432,5 +434,13 @@ IAuthenticationHandler IHttpAuthenticationFeature.Handler
get { return _authHandler; }
set { _authHandler = value; }
}

Guid IRequestIdentifierFeature.TraceIdentifier
{
get
{
return _requestContext.TraceIdentifier;
}
}
}
}
13 changes: 13 additions & 0 deletions src/Microsoft.Net.Http.Server/RequestProcessing/RequestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ internal ulong RequestId
}
}

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need the 1 + anymore?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code from IIS was copying to the first byte location. So I'm following the same so that we generate same guid as HTTP.SYS.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

return guid;
}
}

/// <summary>
/// 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public async Task Request_SimpleGet_Success()
Assert.NotEqual(0, connectionInfo.LocalPort);
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
}
catch (Exception ex)
Expand Down Expand Up @@ -95,12 +100,17 @@ public async Task Request_PathSplitting(string pathBase, string requestPath, str
{
var requestInfo = httpContext.GetFeature<IHttpRequestFeature>();
var connectionInfo = httpContext.GetFeature<IHttpConnectionFeature>();
var requestIdentifierFeature = httpContext.GetFeature<IRequestIdentifierFeature>();

// Request Keys
Assert.Equal("http", requestInfo.Scheme);
Assert.Equal(expectedPath, requestInfo.Path);
Assert.Equal(expectedPathBase, requestInfo.PathBase);
Assert.Equal(string.Empty, requestInfo.QueryString);

// Trace identifier
Assert.NotNull(requestIdentifierFeature);
Assert.NotNull(requestIdentifierFeature.TraceIdentifier);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -135,10 +145,15 @@ public async Task Request_MultiplePrefixes(string requestPath, string expectedPa
{
var httpContext = new DefaultHttpContext((IFeatureCollection)env);
var requestInfo = httpContext.GetFeature<IHttpRequestFeature>();
var requestIdentifierFeature = httpContext.GetFeature<IRequestIdentifierFeature>();
try
{
Assert.Equal(expectedPath, requestInfo.Path);
Assert.Equal(expectedPathBase, requestInfo.PathBase);

// Trace identifier
Assert.NotNull(requestIdentifierFeature);
Assert.NotNull(requestIdentifierFeature.TraceIdentifier);
}
catch (Exception ex)
{
Expand Down