summary refs log tree commit diff
path: root/MxApiExtensions/Extensions/HttpResponseExtensions.cs
blob: 1dd1c0048f8b1a5b041d00cd4e2e595f2df29629 (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.Add(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();
    }
}