mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-15 06:43:37 +01:00
* Add new package WireMock.Net.Extensions.Routing * Update documentation for WireMock.Net.Extensions.Routing * Cleanup imports * Add header to all source files inside WireMock.Net.Extensions.Routing * Add header to all source files inside WireMock.Net.Extensions.Routing.Tests * Revert unintended changes * Remove redundant build configurations * Remove incorrect links from documentation * Update nuget package references * Revert unintended changes * Migrate to AwesomeAssertions * Remove redundant project reference * Adjust formatting * Migrate to primary constructor * Refactoring: rename delegate parameter * Abstract over JSON converter * Replace WireMock with WireMock.Net in comments * Move local functions to the bottom of the methods
35 lines
1.0 KiB
C#
35 lines
1.0 KiB
C#
// Copyright © WireMock.Net
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
using WireMock.Types;
|
|
using WireMock.Util;
|
|
|
|
namespace WireMock.Net.Extensions.Routing.Extensions;
|
|
|
|
internal static class HttpResponseExtensions
|
|
{
|
|
public static async Task<ResponseMessage> ToResponseMessageAsync(
|
|
this HttpResponse response)
|
|
{
|
|
var headers = response.Headers.ToDictionary(
|
|
header => header.Key, header => new WireMockList<string?>(header.Value.ToArray()));
|
|
return new()
|
|
{
|
|
Headers = headers!,
|
|
BodyData = new BodyData
|
|
{
|
|
DetectedBodyType = BodyType.String,
|
|
BodyAsString = await response.ReadBodyAsStringAsync(),
|
|
},
|
|
StatusCode = response.StatusCode,
|
|
};
|
|
}
|
|
|
|
public static async Task<string> ReadBodyAsStringAsync(this HttpResponse response)
|
|
{
|
|
response.Body.Seek(0, SeekOrigin.Begin);
|
|
using var reader = new StreamReader(response.Body);
|
|
return await reader.ReadToEndAsync();
|
|
}
|
|
}
|