mirror of
https://github.com/EpinelPS/EpinelPS.git
synced 2025-12-15 08:24:52 +01:00
refactoring
This commit is contained in:
34
nksrv/Utils/LoggingHttpHandler.cs
Normal file
34
nksrv/Utils/LoggingHttpHandler.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace nksrv.Utils
|
||||
{
|
||||
public class LoggingHttpHandler(HttpMessageHandler innerHandler) : DelegatingHandler(innerHandler)
|
||||
{
|
||||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
Console.WriteLine("Request:");
|
||||
Console.WriteLine(request.ToString());
|
||||
if (request.Content != null)
|
||||
{
|
||||
Console.WriteLine(await request.Content.ReadAsStringAsync(cancellationToken));
|
||||
}
|
||||
Console.WriteLine();
|
||||
|
||||
HttpResponseMessage response = await base.SendAsync(request, cancellationToken);
|
||||
|
||||
Console.WriteLine("Response:");
|
||||
Console.WriteLine(response.ToString());
|
||||
if (response.Content != null)
|
||||
{
|
||||
Console.WriteLine(await response.Content.ReadAsStringAsync(cancellationToken));
|
||||
}
|
||||
Console.WriteLine();
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user