mirror of
https://github.com/Jackett/Jackett.git
synced 2025-12-28 00:04:19 +01:00
39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Jackett.Utils
|
|
{
|
|
class WebAPIRequestLogger : DelegatingHandler
|
|
{
|
|
protected override async Task<HttpResponseMessage> SendAsync(
|
|
HttpRequestMessage request, CancellationToken cancellationToken)
|
|
{
|
|
//logging request body
|
|
string requestBody = await request.Content.ReadAsStringAsync();
|
|
Trace.WriteLine(requestBody);
|
|
Engine.Logger.Debug(request.Method + ": " + request.RequestUri);
|
|
Engine.Logger.Debug("Body: " + requestBody);
|
|
|
|
//let other handlers process the request
|
|
return await base.SendAsync(request, cancellationToken)
|
|
.ContinueWith(task =>
|
|
{
|
|
if (null != task.Result.Content)
|
|
{
|
|
//once response is ready, log it
|
|
var responseBody = task.Result.Content.ReadAsStringAsync().Result;
|
|
Trace.WriteLine(responseBody);
|
|
Engine.Logger.Debug("Response: " + responseBody);
|
|
}
|
|
return task.Result;
|
|
});
|
|
}
|
|
}
|
|
}
|