TLDR: Add HttpTracer to your project and pass a new instance to HttpClient for Fiddler-like http audit/debug capabilities.
What is HttpTracer?
The code was simple enough, a simple DelegatingHandler that you can pass into your HttpClient instance and it would print your app’s http traffic to your debug output. The output would contain the method, url, headers and content for both requests and responses.
After working through issues with the initial implementation and the learning curve with releasing a library to the general public via nuget (this was a first for Daniel and me), we at last had a solid library that worked as advertised out of the box.
We were aware that the library wasn’t perfect and shipping it in a production app bordered on irresponsible. Logging all http traffic from your app is a heavy operation and a potential security risk. I decided to build out a feature that would fine grain control over what was captured and logged.
I started by building a spec: https://github.com/BSiLabs/HttpTracer/issues/34#issue-421978732
After some excellent suggestions from Allan Ritchie and Chase Florell, I built out the verbosity features and published a package to Myget. From there, I was able to test with several real apps to ensure that the library was functioning properly. I fixed my issues, republished, retested and pushed HttpTracer 2.0 on Nuget!
Working on this project has been an excellent learning experience. Owning and maintaining my first open source application has taught me many things about testing, designing libraries for public consumption, nuget packaging, multi-targeting and more.
We are now discussing some wishlist items, like being able to tie into some of the existing logger interfaces that are a part of .NET (currently you would need an adapter class).
I also took some time to try the framework with Blazor. It was a great learning experience as well, being able to work with .NET Core 3.0 for the first time and WASM too! After some stumbles, I was finally able to get HttpTracer working in a small Blazor app, it’s less useful in the context of WASM since you can just use the network tab in developer tools to inspect requests, but it’s still really cool to see the library working with a cutting edge platform!
Check out the gist for Blazor here: https://gist.github.com/dylanberry/8cf04c591ebf81f46a197855316012fe
Thanks for reading and if you have any feedback on HttpTracer, please let me know!