Skip to content

Instantly share code, notes, and snippets.

@cbanner
Created November 21, 2017 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbanner/5c96bb1143912a69a8f3c78666f10421 to your computer and use it in GitHub Desktop.
Save cbanner/5c96bb1143912a69a8f3c78666f10421 to your computer and use it in GitHub Desktop.
An extension method to ASP.NET Core's HttpRequest class, delivering the original request target
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
/// <summary>
/// Gets the raw target of an HTTP request.
/// </summary>
/// <returns>Raw target of an HTTP request</returns>
/// <remarks>
/// ASP.NET Core manipulates the HTTP request parameters exposed to pipeline
/// components via the HttpRequest class. This extension method delivers an untainted
/// request target. https://tools.ietf.org/html/rfc7230#section-5.3
/// </remarks>
public static string GetRawTarget(this HttpRequest request)
{
var httpRequestFeature = request.HttpContext.Features.Get<IHttpRequestFeature>();
return httpRequestFeature.RawTarget;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment