summary refs log tree commit diff
path: root/MxApiExtensions/Extensions/HttpResponseExtensions.cs
blob: 3f776ec8eea9046c2eceb9c1e84b7ef480b0dcf3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
namespace MxApiExtensions.Extensions;

public static class HttpResponseExtensions {
    public static async Task WriteHttpResponse(this HttpResponse response, HttpResponseMessage message) {
        response.StatusCode = (int)message.StatusCode;
        //copy all headers
        foreach (var header in message.Headers) {
            response.Headers.Append(header.Key, header.Value.ToArray());
        }

        await response.StartAsync();
        var content = await message.Content.ReadAsStreamAsync();
        await content.CopyToAsync(response.Body);
        await response.CompleteAsync();
        // await content.DisposeAsync();
    }
}