24 lines
		
	
	
		
			911 B
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
		
			911 B
		
	
	
	
		
			C#
		
	
	
	
	
	
| using Microsoft.AspNetCore.Http;
 | |
| 
 | |
| namespace Core.Cerberos.Adapters.Extensions
 | |
| {
 | |
|     public sealed class TrackingMechanismExtension : DelegatingHandler
 | |
|     {
 | |
|         private readonly IHttpContextAccessor _httpContextAccessor;
 | |
| 
 | |
|         public TrackingMechanismExtension(IHttpContextAccessor httpContextAccessor)
 | |
|         {
 | |
|             _httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
 | |
|         }
 | |
| 
 | |
|         protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
 | |
|         {
 | |
|             if (_httpContextAccessor.HttpContext.Items.TryGetValue("TrackingId", out var trackingId))
 | |
|             {
 | |
|                 request.Headers.Add("TrackingId", trackingId.ToString());
 | |
|             }
 | |
|             return await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
 | |
|         }
 | |
|     }
 | |
| }
 | 
