Skip to main content

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 IHttpContextAccessor and forwards critical headers to the outgoing request. Specifically, it propagates:
    • The Authorization header, to maintain the user's authentication context across services.
    • The x-request-id header (falling back to HttpContext.TraceIdentifier when the x-request-id value is not available), to ensure end-to-end traceability of a request as it travels through multiple services.
  • 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 DelegatingHandler logs the details of outgoing HTTP requests and their responses as structured logs (using the HttpRequestLogTemplate/HttpResponseLogTemplate models from RA.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.