mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-18 06:29:38 +02:00
Add .ConfigureAwait(false); to the await Task calls (#704)
Add .ConfigureAwait(false); to the await Task calls
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
#if !USE_ASPNETCORE
|
||||
@@ -52,19 +52,22 @@ namespace WireMock.Owin
|
||||
public Task Invoke(IContext ctx)
|
||||
#endif
|
||||
{
|
||||
return InvokeInternal(ctx);
|
||||
return InvokeInternalAsync(ctx);
|
||||
}
|
||||
|
||||
private async Task InvokeInternal(IContext ctx)
|
||||
private async Task InvokeInternalAsync(IContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
await Next?.Invoke(ctx);
|
||||
if (Next != null)
|
||||
{
|
||||
await Next.Invoke(ctx).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_options.Logger.Error("HttpStatusCode set to 500 {0}", ex);
|
||||
await _responseMapper.MapAsync(ResponseMessageBuilder.Create(JsonConvert.SerializeObject(ex), 500), ctx.Response);
|
||||
await _responseMapper.MapAsync(ResponseMessageBuilder.Create(JsonConvert.SerializeObject(ex), 500), ctx.Response).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ using WireMock.Handlers;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Util;
|
||||
using JetBrains.Annotations;
|
||||
#if !USE_ASPNETCORE
|
||||
using Owin;
|
||||
#else
|
||||
|
||||
@@ -65,25 +65,25 @@ namespace WireMock.Owin.Mappers
|
||||
DecompressGZipAndDeflate = !options.DisableRequestBodyDecompressing.GetValueOrDefault(false)
|
||||
};
|
||||
|
||||
body = await BodyParser.Parse(bodyParserSettings);
|
||||
body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return new RequestMessage(urlDetails, method, clientIP, body, headers, cookies) { DateTime = DateTime.UtcNow };
|
||||
}
|
||||
|
||||
private (UrlDetails UrlDetails, string ClientIP) ParseRequest(IRequest request)
|
||||
private static (UrlDetails UrlDetails, string ClientIP) ParseRequest(IRequest request)
|
||||
{
|
||||
#if !USE_ASPNETCORE
|
||||
var urldetails = UrlUtils.Parse(request.Uri, request.PathBase);
|
||||
var urlDetails = UrlUtils.Parse(request.Uri, request.PathBase);
|
||||
string clientIP = request.RemoteIpAddress;
|
||||
#else
|
||||
var urldetails = UrlUtils.Parse(new Uri(request.GetEncodedUrl()), request.PathBase);
|
||||
var urlDetails = UrlUtils.Parse(new Uri(request.GetEncodedUrl()), request.PathBase);
|
||||
var connection = request.HttpContext.Connection;
|
||||
string clientIP = connection.RemoteIpAddress.IsIPv4MappedToIPv6
|
||||
? connection.RemoteIpAddress.MapToIPv4().ToString()
|
||||
: connection.RemoteIpAddress.ToString();
|
||||
#endif
|
||||
return (urldetails, clientIP);
|
||||
return (urlDetails, clientIP);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
@@ -103,7 +103,7 @@ namespace WireMock.Owin.Mappers
|
||||
|
||||
if (bytes != null)
|
||||
{
|
||||
await response.Body.WriteAsync(bytes, 0, bytes.Length);
|
||||
await response.Body.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ using System;
|
||||
using System.Threading.Tasks;
|
||||
using WireMock.Logging;
|
||||
using System.Linq;
|
||||
using HandlebarsDotNet.Helpers.Utils;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Http;
|
||||
using WireMock.Owin.Mappers;
|
||||
@@ -70,7 +69,7 @@ namespace WireMock.Owin
|
||||
|
||||
private async Task InvokeInternalAsync(IContext ctx)
|
||||
{
|
||||
var request = await _requestMapper.MapAsync(ctx.Request, _options);
|
||||
var request = await _requestMapper.MapAsync(ctx.Request, _options).ConfigureAwait(false);
|
||||
|
||||
var logRequest = false;
|
||||
ResponseMessage response = null;
|
||||
@@ -115,22 +114,22 @@ namespace WireMock.Owin
|
||||
|
||||
if (!targetMapping.IsAdminInterface && _options.RequestProcessingDelay > TimeSpan.Zero)
|
||||
{
|
||||
await Task.Delay(_options.RequestProcessingDelay.Value);
|
||||
await Task.Delay(_options.RequestProcessingDelay.Value).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
var (theResponse, theOptionalNewMapping) = await targetMapping.ProvideResponseAsync(request);
|
||||
var (theResponse, theOptionalNewMapping) = await targetMapping.ProvideResponseAsync(request).ConfigureAwait(false);
|
||||
response = theResponse;
|
||||
|
||||
var responseBuilder = targetMapping.Provider as Response;
|
||||
|
||||
if (!targetMapping.IsAdminInterface && theOptionalNewMapping != null)
|
||||
{
|
||||
if (responseBuilder?.ProxyAndRecordSettings?.SaveMapping == true || targetMapping?.Settings?.ProxyAndRecordSettings?.SaveMapping == true)
|
||||
if (responseBuilder?.ProxyAndRecordSettings?.SaveMapping == true || targetMapping.Settings?.ProxyAndRecordSettings?.SaveMapping == true)
|
||||
{
|
||||
_options.Mappings.TryAdd(theOptionalNewMapping.Guid, theOptionalNewMapping);
|
||||
}
|
||||
|
||||
if (responseBuilder?.ProxyAndRecordSettings?.SaveMappingToFile == true || targetMapping?.Settings?.ProxyAndRecordSettings?.SaveMappingToFile == true)
|
||||
if (responseBuilder?.ProxyAndRecordSettings?.SaveMappingToFile == true || targetMapping.Settings?.ProxyAndRecordSettings?.SaveMappingToFile == true)
|
||||
{
|
||||
var matcherMapper = new MatcherMapper(targetMapping.Settings);
|
||||
var mappingConverter = new MappingConverter(matcherMapper);
|
||||
@@ -187,10 +186,10 @@ namespace WireMock.Owin
|
||||
// Empty catch
|
||||
}
|
||||
|
||||
await _responseMapper.MapAsync(response, ctx.Response);
|
||||
await _responseMapper.MapAsync(response, ctx.Response).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await CompletedTask;
|
||||
await CompletedTask.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task SendToWebhooksAsync(IMapping mapping, RequestMessage request, ResponseMessage response)
|
||||
|
||||
Reference in New Issue
Block a user