Skip to content

Instantly share code, notes, and snippets.

@luisgoncalves
Created September 5, 2018 16:28
Show Gist options
  • Save luisgoncalves/4f7dedf6e4a7c8aaa6a053f23d103c0e to your computer and use it in GitHub Desktop.
Save luisgoncalves/4f7dedf6e4a7c8aaa6a053f23d103c0e to your computer and use it in GitHub Desktop.
DumpToConsoleDelegatingHandler
class DumpToConsoleDelegatingHandler : DelegatingHandler
{
public DumpToConsoleDelegatingHandler()
{
InnerHandler = new HttpClientHandler();
}
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
Console.WriteLine("");
Console.WriteLine("==> {0} {1}", request.Method, request.RequestUri);
Console.WriteLine(string.Join("\n", request.Headers.Select(h => h.Key + ": " + string.Join(", ", h.Value))));
var res = await base.SendAsync(request, cancellationToken);
Console.WriteLine("{0} {1}", res.StatusCode, res.ReasonPhrase);
Console.WriteLine(string.Join("\n", res.Headers.Select(h => h.Key + ": " + string.Join(", ", h.Value))));
//Console.WriteLine(await res.Content.ReadAsStringAsync());
Console.WriteLine("<==");
return res;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment