Skip to content

Commit 9a7d499

Browse files
feature(#6): this commit implements the correlation interceptor for correct propagation of the correlation identifier in http clients.
1 parent e1b7d3f commit 9a7d499

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace Comanda.Orchestrator.WebApi.Interceptors;
2+
3+
public sealed class CorrelationInterceptor(IHttpContextAccessor accessor) : DelegatingHandler
4+
{
5+
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
6+
{
7+
var correlation = accessor.HttpContext?.Items[Headers.Correlation]?.ToString();
8+
9+
if (!string.IsNullOrWhiteSpace(correlation))
10+
{
11+
request.Headers.Remove(Headers.Correlation);
12+
request.Headers.Add(Headers.Correlation, correlation);
13+
}
14+
15+
return await base.SendAsync(request, cancellationToken);
16+
}
17+
}

0 commit comments

Comments
 (0)