Created
September 5, 2018 16:28
-
-
Save luisgoncalves/4f7dedf6e4a7c8aaa6a053f23d103c0e to your computer and use it in GitHub Desktop.
DumpToConsoleDelegatingHandler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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