Git Product home page Git Product logo

httptracer's Introduction

HttpTracer

A simple http tracing library to write request and response information to your output window. Making your life easier when debugging http calls!

Channel Status
Build Build status
MyGet.org #
NuGet.org #

Platform Support

Http Tracer is a .NET Standard 2.0 library.

Platform Version
Xamarin.iOS iOS 7+
Xamarin.Android API 14+
Windows 10 UWP 10.0.16299+
.NET Core 2.0+
ASP.NET Core 2.0+
.NET 4.6.1+

Getting Started

It is really easy to start using and debugging your Http requests, just add a instance of HttpTracerHandler to your HttpClient creation and start picking up the traces in your Visual Studio console window.

using HttpTracer;
public async Task GetMyData()
{
    var tracer = new HttpTracerHandler
    {
        Verbosity = HttpMessageParts.All
    };
    var client = new HttpClient(tracer);
    var result = await client.GetAsync("http://myserviceurl.com");
}

If you happen to use custom Http Handlers in your project, we suggest you use our Http handler builder:

using HttpTracer;
public async Task GetMyData()
{
    var builder = new HttpHandlerBuilder();

    builder.AddHandler(new MyHandler3())
           .AddHandler(new MyHandler2())
           .AddHandler(new MyHandler1());
           
    var tracer = builder.Build();
    tracer.Verbosity = HttpMessageParts.All;
    
    var client = new HttpClient(tracer);
    var result = await client.GetAsync("http://myserviceurl.com");
}

You can use bitwise operators to combine your desired HttpMessagePart options:

private const HttpMessageParts DefaultHttpTracerVerbosity =
            HttpMessageParts.RequestAll | HttpMessageParts.ResponseHeaders;

You can set the verbosity for all of your HttpTracerHandler instances by setting HttpTracerHandler.DefaultVerbosity. To set verbosity at the per-instance level, use HttpTracerHandler.Verbosity which will override HttpTracerHandler.DefaultVerbosity.

Replaying Requests

The output format for requests can be copy/pasted into a compatible rest client such as REST Client for Visual Studio Code or the REST Client which is part of JetBrains IDEs (Rider, PyCharm, Android Studio, etc).

License

Under MIT (see license file)

Want To Support This Project?

All we ask is to be active by submitting bugs, features, and sending those pull requests down!

httptracer's People

Contributors

aritchie avatar chaseflorell avatar danielcauser avatar dylanberry avatar mfkl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

httptracer's Issues

[Spec] Allow Verbosity to be changed

Summary

Writing all request and response data can be a heavy operation. We need a mechanism to control verbosity on the fly.

API

HttpMessageParts Flags

[Flags]
public enum HttpMessageParts
{
    Unknown = 0
    None = 1,

    RequestBody = 2,
    RequestHeaders = 4,
    RequestAll = RequestBody | RequestHeaders,

    ResponseBody = 8,
    ResponseHeaders = 16,

    ResponseAll = ResponseBody | ResponseHeaders,

    All = ResponseAll | RequestAll
}

HttpTracerHandler Public Property

public HttpMessageParts Verbosity { get; set; } = HttpMessageParts.RequestAll | HttpMessageParts.ResponseHeaders;

HttpTracerHandler Public Static Property

NOTE: we must validate this is not set to HttpMessageParts.Unknown

public static HttpMessageParts DefaultVerbosity { get; set; } = HttpMessageParts.Unknown;

Usage

The developer will need to ensure the HttpTracerHandler instance is available in order to change the verbosity on the fly.

using HttpTracer;
public async Task GetMyData()
{
    var tracer = new HttpTracerHandler();
    tracer.Verbosity = HttpMessageParts.RequestHeaders | HttpMessageParts.ResponseHeaders;
    var client = new HttpClient(tracer);
    var result = await client.GetAsync("http://myserviceurl.com");
}

[Enhancement] JSON Response appearing indented as JSON

Sup guys!
I am not sure if this is already possible, but I am not able to figure out if using the package I can make my JSON response appear as indented JSON, so that it's easier to read. Currently I have to

  1. Copy the response I get:

image

  1. Paste it into VS Code,
  2. Remove the Debug stuff in the beginning of the lines that come after the first line
  3. Remove the line breaks and put all of the response in one line
  4. Then paste it into https://jsonformatter.curiousconcept.com/ and click "Process"

Which is a lot of steps, so it would be awesome if there was a way to just change the config so HttpTracer does that!

Is it possible to use this with RestSharp?

I love HTTPTracer and use it for my http clients, but if I'm using RESTSharp, how can I use HttpTracer?

RestSharp using var client = new RestClient( instead of httpclient

Multi Targeting

Hey guys, we should think of making this lib multi target other versions of the net framework.

HttpClient not returning data, logging response or throwing exception

Description

HttpClient not returning data, logging response or throwing exception.

Steps to Reproduce

Tested on iOS iPhone X 11.3 Simulator

const string url = "https://www.meetup.com/TorontoMobileDevelopers/events/rss/";
using (var client = new HttpClient(new TestHttpTracer.HttpTracerHandler()))
{
    var result = await client.GetStringAsync(url).ConfigureAwait(false);
}

Result is null, but should match the response from the url as seen via the browser.

Expected Behavior

HttpClient returns data and logs response.

Actual Behavior

HttpClient returns null and does not log or throw an exception.

Basic Information

=== Visual Studio Enterprise 2017 for Mac ===

Version 7.5.1 (build 22)
Installation UUID: d5d95059-9c23-453f-ab75-c9e751d1512f
Runtime:
	Mono 5.10.1.47 (2017-12/8eb8f7d5e74) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)
	Xamarin.Mac 4.4.1.178 (master / eeaeb7e6)

	Package version: 510010047

=== NuGet ===

Version: 4.3.1.4445

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	2.0.5
	2.0.0-preview2-25407-01
	1.1.2
	1.0.5
SDK: /usr/local/share/dotnet/sdk/2.1.4/Sdks
SDK Versions:
	2.1.4
	2.0.0-preview2-006497
	1.0.4
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.10.1/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.2
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 9.3.1 (14154.1)
Build 9E501

=== Xamarin.Mac ===

Version: 4.4.1.178 (Visual Studio Enterprise)

=== Xamarin.Android ===

Version: 8.3.0.19 (Visual Studio Enterprise)
Android SDK: /Users/dylanberry/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		5.1 (API level 22)
		6.0 (API level 23)
		7.0 (API level 24)
		7.1 (API level 25)
		8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 27.0.1
SDK Build Tools Version: 27.0.3

Java SDK: /usr
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin.iOS ===

Version: 11.10.1.178 (Visual Studio Enterprise)
Hash: 408d3574
Branch: d15-7
Build date: 2018-05-08 18:56:30-0400

=== Xamarin Inspector ===

Version: 1.4.0
Hash: b3f92f9
Branch: master
Build date: Fri, 19 Jan 2018 22:00:34 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 705010022
Git revision: 60442dd643a20c7a4ae1f8705b8d1de8972eee78
Build date: 2018-05-15 01:43:39+00
Xamarin addins: 4194ffe4868321e4c3477bd56aed579bda4c6fbb

=== Operating System ===

Mac OS X 10.13.4
Darwin 17.5.0 Darwin Kernel Version 17.5.0
    Mon Mar  5 22:24:32 PST 2018
    root:xnu-4570.51.1~1/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

MFractor 3.05.12
Internet of Things (IoT) development (Preview) 7.5

trouble getting started, Visual Studio + Refit example

Hi there, I found your library in the course of trying to troubleshoot a Refit issue. It's one of those cases where I can make it work in Postman, but I'm not sure how to reproduce it correctly for Refit. The issue is I'm not seeing any trace output in the Debug window when I run my project. I've made a little walkthrough:

https://1drv.ms/u/s!AvguHRnyJtWMmeh7C8wHrd7X8BbDyA?e=tcCcNZ

Here's my relevant code:
https://github.com/adamfoneil/GitHubApi/blob/master/MicropubApi.Library/MicropubApiClient.cs#L17

[Enhancement] Expose Methods for preprocessing data

In many scenarios, we might need to preprocess a string before logging it. This would be for things like removing bearer tokens from headers or truncating large content bodies.

This feature request is to give us access to that data before logging it.

Incompatible with .NETPortable Framework

Hey @DanielCauser, @dylanberry, @ChaseFlorell !
I was excited to add this package into my project when I saw you guys speak about it, but I am getting the following error:

NU1202: Package HttpTracer 1.0.3 is not compatible with portable45-net45+win8+wpa81 (.NETPortable,Version=v4.5,Profile=Profile111). Package HttpTracer 1.0.3 supports:

  • netstandard1.4 (.NETStandard,Version=v1.4)
  • netstandard2.0 (.NETStandard,Version=v2.0)

Is there a way to still add it somehow without changing the Target Framework?

Save request/response and replay

Hi!
I really like this project, could this be used for testing?
Is there any planned feature for saving requests and responses to disk? And then used that saved data to replay the request, for testing purpose?

Should the Log methods all be FireAndForget?

Making the log methods async void or some other form of FireAndForget will increase log performance as it's not actually waiting for the deserializing of the string before the result is returned to the caller.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.