-
Notifications
You must be signed in to change notification settings - Fork 1
/
PackageDataHelper.cs
33 lines (31 loc) · 1.24 KB
/
PackageDataHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Linq;
using System.Net.Http;
using LaserCatEyes.DataServiceSdk.DotNetStandard;
using LaserCatEyes.Domain.Models;
namespace LaserCatEyes.HttpClientListener.DotNetStandard
{
public static class PackageDataHelper
{
public static PackageData RequestPackageDataFromHttpRequestMessage(Guid id, HttpRequestMessage request)
{
return PackageData.CreateRequestPackage(
id,
request.RequestUri.ToString(),
Utilities.HttpMethodStringToEnumConverter(request.Method.Method),
request.Headers.SelectMany(r => r.Value.Select(value => $"{r.Key}:{value}")).ToList(),
request.Content?.ReadAsStringAsync().Result,
DateTime.UtcNow,
null,
null);
}
public static PackageData ResponsePackageDataFromHttpResponseMessage(Guid id, HttpResponseMessage response)
{
return PackageData.CreateResponsePackage(
id,
(int) response.StatusCode, response.Headers.SelectMany(r => r.Value.Select(value => $"{r.Key}:{value}")).ToList(),
response.Content.ReadAsStringAsync().Result,
DateTime.UtcNow);
}
}
}