-
Notifications
You must be signed in to change notification settings - Fork 2
/
LogHandler.cs
24 lines (20 loc) · 1.24 KB
/
LogHandler.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
using System;
internal static class LogHandler
{
public static string ReadSanitizedRequest(FlurlCall call)
{
string verb = call.Request.Verb.ToString();
string path = call.Request.Url;
string headers = string.Join(Environment.NewLine, call.Request.Headers.Select((name, index) => $"{index + 1}: {name}"));
string body = call.Request.Url.Path == "/gateway/deal/session" ? "*******" : call.RequestBody.JsonPrettify();
return $"--> HTTP {verb} {call.Request.Url}{Environment.NewLine}HEADERS:{Environment.NewLine}{headers}{Environment.NewLine}BODY:{Environment.NewLine}:{body}";
}
public static async Task<string> ReadResponse(FlurlCall call)
{
var response = await call.Response.ResponseMessage.Content.ReadAsStringAsync();
var status = call.Response.ResponseMessage?.StatusCode;
string headers = string.Join(Environment.NewLine, call.Response?.Headers?.Select((name, index) => $"{index + 1}: {name}"));
double? duration = call.Completed ? call.Duration?.TotalMilliseconds : 0;
return $"<-- HTTP {status} [{call}] [duration:{duration}ms]{Environment.NewLine}HEADERS:{Environment.NewLine}{headers}{Environment.NewLine}BODY:{Environment.NewLine}:{response}";
}
}