Sphyrnidae Common Library  2.0.1
Shared Utilities/Library
Http Client

Overview

The IHttpClientSettings is meant to abstract out communication with an HTTP Request. This interface basically works by allowing other abstractions to retrieve data from the HTTP Request via this abstraction. If you'd like to change the location of information in a HTTP Request, you can do so by updating this class. Most of the properties on this interface are the name of an HTTP Header, and a Get property to retrieve information from that property. Other components will use this interface to set these values in outgoing HTTP Responses.

The IHttpClientSettings interface has the following properties. The table below shows all properties, and what the default implementation does to implement.

Property Default Implementation Where used
ContentType MediaTypeNames.Application.Json None - this has been moved to ServiceConfiguration which is defaulted to JSON responses.
JwtHeader "Authorization" JwtMiddleware: Sets the refreshed JWT into this header
Api Logging: When logging the API request headers, this header will always be obfuscated
WebServiceBase: Sets the JWT into this header for the outgoing HTTP Request
Jwt
  1. Reads from JwtHeader
  2. Reads from Querystring "access_token"
  3. Removes "bearer" (with or without spaces)
IdentityHelper: Obtains this JWT to convert to Identity
RequestIdHeader "V-Correlation-Id" WebServiceBase: Where the requestId goes in the header for the outgoing HTTP Request
RequestId
  1. Reads from RequestIdHeader
  2. Obtains this from Request Data
Logging: This value is always logged
WebServiceBase: Retrieves this to forward into outgoing HTTP Request
SessionIdHeader "X-Tracking-Id" WebServiceBase: Where the sessionId goes in the header for the outgoing HTTP Request
SessionId Reads from SessionIdHeader Logging: This value is always logged
WebServiceBase: Retrieves this to forward into outgoing HTTP Request
IpAddressHeader "X-Forwarded-For" WebServiceBase: Where the IP Address goes in the header for the outgoing HTTP Request
IpAddress
  1. Pulls from Request Data (IpAddress)
  2. Reads from IpAddressHeader
  3. Pulls from Request Data (RemoteIpAddress)
  4. "unknown"
  5. For whatever value is pulled back, this will be "cleaned": Localhost check, strips out the domain
WebServiceBase: Retrieves this to forward into outgoing HTTP Request
LogOrderHeader "X-Logging-Order" Logging: This value is always logged. The logger will also be responsible for placing the LogOrder into this header for web service requests
LogOrder Reads from LogOrderHeader Logging: The existing value will be the prefix to the new value set into the header of outgoing HTTP requests. This value is also always logged.
BearerAndLocalhostComparison StringComparison.CurrentCultureIgnoreCase Jwt: To strip out "bearer"
IpAddress: To check for "localhost"

Interface: IHttpClientSettings

Mock: HttpClientSettingsMock

Implementation: HttpClientSettings

Examples

    IHttpClient http; // Should be injected
    var ipAddress = http.IpAddress;

    HttpHeaders headers; // Should be retrieved from the new HttpRequest object
    headers.Add(http.RequestIdHeader, http.RequestId);