Sphyrnidae Common Library  2.0.1
Shared Utilities/Library
Request Data

Overview

The IRequestData interface provides a number of methods for accessing HttpRequest data. The implementation is registered as request-scoped, and pulls everything it needs from IHttpData. Because of this dependency, many of these methods are not thread-safe (eg. will cause exceptions if the main thread has returned and the context has been disposed). Note that all of these properties do directly access the HttpRequest object, which does not account for these values being passed along in headers (see Http Client).

Interface: IRequestData

Mock: RequestDataMock

Implementation: RequestData

Property Description Implementation
Id Gets the unique ID for the request (Typically called a CorrelationId) Guid.NewGuid()
LoggingOrder Order of things being logged (char)33 - will be incremented every time logging occurs
IpAddress Ip Address of the end user/client None - just a place to set/get this property
RemoteIpAddress IP Address of the machine making this request (may not be the original) IpAddress
DisplayUrl The base URL of the request HttpRequest.GetDisplayUrl()
Route Route of an API Request Route template for a controller action
ContentData() The raw content data of the request GetBodyAsync
HttpVerb The Http Verb for the request HttpRequest.Method
Headers Collection of Http Headers HttpRequest.Headers.ToNameValueCollection()
QueryString Collection of QueryString variables HttpRequest.Query
FormData Collection of Form variables HttpRequest.Form
Browser Name/Description of the client browser HttpRequest.Headers["User-Agent"]
T GetEndpointObject<T>() Retrieves some object about the actual endpoint HttpContext.Features.Get<IEndpointFeature>().Endpoint.Metadata - locate T within collection
GetHeader() Retrieves an HTTP Header from the request GetHeader
GetHeaders() The collection of HTTP Headers with the given name HttpRequest.Headers[name] ?? default

Where Used

  1. AuthenticationMiddleware: Retrieving authentication headers and the AuthenticationAttribute
  2. HttpDataMiddleware: Retrieval of SkipLogAttribute
  3. HttpClientSettings: The implementation of IHttpClientSettings will check against provided values in the HTTP headers, or against the request object
  4. ApiInformation (see Logging): Obtains a number of items to be logged
  5. LoggerInformation (see Logging): Also gets a number of things to be logged, and also updates LoggingOrder

Examples

Compare this to Http Data

    IRequestData request; // Should be injected
    var httpVerb = request.HttpVerb;