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 header propagation and logging before the request is sent.
Here is a breakdown of the purpose of each class in that namespace:
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 (falling back toHttpContext.TraceIdentifierwhen thex-request-idvalue is not available), 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.
LoggingHandler
- Purpose:
This
DelegatingHandlerlogs the details of outgoing HTTP requests and their responses as structured logs (using theHttpRequestLogTemplate/HttpResponseLogTemplatemodels fromRA.Utilities.Logging.Shared), including method, URI, headers, body, and status code. - Use Case:
Attach it with
AddLoggingHandler()to get a complete audit trail of every call an integration makes — invaluable for debugging external API failures.
InternalHeadersForwardHandler
The InternalHeadersForwardHandler is a
LoggingHandler
The LoggingHandler is a DelegatingHandler