Created
December 2, 2018 01:30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TenantInterceptor | |
{ | |
private const string TenantHeader = "x-tenant-id"; | |
private readonly RequestDelegate _next; | |
public TenantInterceptor(RequestDelegate next) | |
{ | |
_next = next; | |
} | |
public async Task Invoke(HttpContext httpContext) | |
{ | |
if (httpContext.Request.Headers.TryGetValue(TenantHeader, out var tenantHeaders)) | |
{ | |
var tenantId = tenantHeaders.First(); | |
httpContext.Items[TenantHeader] = tenantId; | |
} | |
await _next(httpContext); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment