mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-23 09:30:59 +01:00
Enable support for WireMock Middleware in Hosted Services (#1285)
This commit is contained in:
committed by
GitHub
parent
0fd190b5a3
commit
9392069f8a
@@ -36,7 +36,6 @@ internal class WireMockDelegationHandler : DelegatingHandler
|
||||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
Guard.NotNull(request);
|
||||
Guard.NotNull(_httpContextAccessor.HttpContext);
|
||||
|
||||
if (_settings.AlwaysRedirect || IsWireMockRedirectHeaderSetToTrue())
|
||||
{
|
||||
@@ -57,16 +56,30 @@ internal class WireMockDelegationHandler : DelegatingHandler
|
||||
|
||||
private bool IsWireMockRedirectHeaderSetToTrue()
|
||||
{
|
||||
var httpContext = _httpContextAccessor.HttpContext;
|
||||
if (httpContext is null)
|
||||
{
|
||||
_logger.LogDebug("HttpContext is not available in current runtime environment");
|
||||
return false;
|
||||
}
|
||||
|
||||
return
|
||||
_httpContextAccessor.HttpContext!.Request.Headers.TryGetValue(AppConstants.HEADER_REDIRECT, out var values) &&
|
||||
httpContext.Request.Headers.TryGetValue(AppConstants.HEADER_REDIRECT, out var values) &&
|
||||
bool.TryParse(values.ToString(), out var shouldRedirectToWireMock) && shouldRedirectToWireMock;
|
||||
}
|
||||
|
||||
private bool TryGetDelayHeaderValue(out int delayInMs)
|
||||
{
|
||||
delayInMs = 0;
|
||||
var httpContext = _httpContextAccessor.HttpContext;
|
||||
if (httpContext is null)
|
||||
{
|
||||
_logger.LogDebug("HttpContext is not available in current runtime environment");
|
||||
return false;
|
||||
}
|
||||
|
||||
return
|
||||
_httpContextAccessor.HttpContext!.Request.Headers.TryGetValue(AppConstants.HEADER_RESPONSE_DELAY, out var values) &&
|
||||
httpContext.Request.Headers.TryGetValue(AppConstants.HEADER_RESPONSE_DELAY, out var values) &&
|
||||
int.TryParse(values.ToString(), out delayInMs);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user