DelegatingHandler
The RA.Utilities.Integrations.DelegatingHandlers namespace contains classes that act as middleware for
HttpClient instances.
These handlers intercept outgoing HTTP requests to add functionality like authentication, header propagation, and logging before the request is sent.
Here is a breakdown of the purpose of each class in that namespace:
ApiKeyAuthenticationHandler<TSettings>
- Purpose:
This is a
DelegatingHandlerdesigned to automate API key authentication. It retrieves an API key from a configured settings object (any class that implementsIApiKeySettings) and automatically adds it to theX-Api-Keyheader of every outgoing request. - Use Case:
This is ideal for integrations with external APIs that require a static API key for authentication.
By adding this handler to the
HttpClientpipeline, you don't need to manually add the key to every request you make.
InternalHeadersForwardHandler
- Purpose:
This handler is designed for internal, service-to-service communication within a microservices architecture.
It accesses the current incoming request's context via
IHttpContextAccessorand forwards critical headers to the outgoing request. Specifically, it propagates:- The
Authorizationheader, to maintain the user's authentication context across services. - The
x-request-idheader (or theTraceIdentifieras a fallback), to ensure end-to-end traceability of a request as it travels through multiple services.
- The
- Use Case: When Service A receives a request from a user and needs to call Service B to fulfill it, this handler ensures that Service B receives the original user's credentials and the same tracing ID, making security and logging consistent.
ProxyMessageHandler
- Purpose:
This is a factory class, not a delegating handler.
Its sole responsibility is to create and configure the primary
HttpClientHandlerwith proxy settings. AnHttpClient's proxy must be set on its innermost handler, which is why this logic is separated from the chain of delegating handlers. - How it Works: It takes an
IProxySettingsobject and, if a proxy address is specified, it constructs anHttpClientHandlerwith aWebProxyinstance, including credentials if they are provided. If no proxy is configured, it returns a default handler. - Use Case:
This factory is used by the dependency injection extensions when setting up an
HttpClient. It allows integrations to transparently route traffic through a corporate or development proxy based on configuration, without the application code needing to be aware of it.
📄️ ApiKeyAuthenticationHandler
The ApiKeyAuthenticationHandler is a specialized piece of middleware for
📄️ InternalHeadersForwardHandler
The InternalHeadersForwardHandler is a
📄️ ProxyMessageHandler
First, a key clarification: ProxyMessageHandler is a static factory class, not a
📄️ RequestResponseLoggingHandler
The RequestResponseLoggingHandler is a DelegatingHandler