Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I have a little suggestion about httpclient #208

Closed
jakey188 opened this issue Jan 29, 2018 · 10 comments

Comments

@jakey188
Copy link

@jakey188 jakey188 commented Jan 29, 2018

Hi Tom
I want to have a free record, requesturl,httpmethod,network time consuming
but ocelot not customizable delegatinghandler
i want to httpclient more flexible. i will be in delegatinghandler do more anything
Is it possible to consider the implementation

@TomPallister

This comment has been minimized.

Copy link
Member

@TomPallister TomPallister commented Jan 29, 2018

@jakey188

I do not understand fully what you want to do.

At the moment I do not plan to change how the HttpClient works!

However you can do whatever you want with Ocleot because all of its service are registered with TryAdd which means if you have already added the interface and implementation .net will not try to do it again.

This means that you can override any of the services.

IHttpRequester is responsible for returning the HttpResponseMessage to the Ocelot pipeline. Therefore you can provide your own implementation of this interface and register is before adding the ocelot services.

e.g.

services.AddJakeyHttpClient();
services.AddOcelot();

Alternatively if you want to contribute to Ocelot you could change HttpClientHttpRequester to take IHttpClientBuilder as a dependency and rather than new up HttpClientBuilder and override this.

I hope this helps.

@jakey188

This comment has been minimized.

Copy link
Author

@jakey188 jakey188 commented Jan 31, 2018

@TomPallister
I want to record all the request http information.
`public class HttpTracingDelegatingHandler : DelegatingHandler
{

    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        var method =  request.Method;
        var requestUrl = request.RequestUri.ToString();
        //db.Save(method,requestUrl);
        //or do some other things
        return base.SendAsync(request, cancellationToken);
    }
}`

now I need to take HttpTracingDelegatingHandler join in HttpClient

var _handlers = new Dictionary<int, Func>();
_handlers.Add(1000, () => new HttpTracingDelegatingHandler());
HttpMessageHandler httpMessageHandler = new HttpClientHandler();
_handlers
.OrderByDescending(handler => handler.Key)
.Select(handler => handler.Value)
.Reverse()
.ToList()
.ForEach(handler =>
{
var delegatingHandler = handler();
delegatingHandler.InnerHandler = httpMessageHandler;
httpMessageHandler = delegatingHandler;
});
return new HttpClient(httpMessageHandler);

@jakey188

This comment has been minimized.

Copy link
Author

@jakey188 jakey188 commented Jan 31, 2018

I need http tracing . including all services and ocelot

@TomPallister

This comment has been minimized.

Copy link
Member

@TomPallister TomPallister commented Jan 31, 2018

@jakey188 OK we might be able to expose the handlers dictionary? I can have a look at this at some point in the future.

However if you need tracing @geffzhang is looking into using distributed tracing butterfly in this issue #19 so that might be better?

@jakey188

This comment has been minimized.

Copy link
Author

@jakey188 jakey188 commented Feb 1, 2018

yes ,we might be able to expose the handlers dictionary for use butterfly .

@geffzhang

This comment has been minimized.

Copy link
Contributor

@geffzhang geffzhang commented Feb 4, 2018

@jakey188 You can add me wechat geffzhang. I have added Httptracingdelegatinghandler https://github.com/geffzhang/Ocelot/blob/Monitoring/src/Ocelot/Tracing/OcelotHttpTracingHandler.cs , have basically completed and butterfly integration work, but there are test work and ocelot tracing buried point work to do, we can together to improve。 We are mainly here #19 to discuss this work

@TomPallister

This comment has been minimized.

Copy link
Member

@TomPallister TomPallister commented Feb 10, 2018

@jakey188 please look at #224 this is my idea to implement your request. DelegatingHandlers now exposed...

s.AddOcelot()
                    .AddDelegatingHandler(() => new FakeHandler())
                    .AddDelegatingHandler(() => new FakeHandler());

The delegating handlers are run in order of addition so FIFO if you are using QoS feature of Ocelot that will always be last.

Let me know if you have any suggestions.

@jakey188

This comment has been minimized.

Copy link
Author

@jakey188 jakey188 commented Feb 11, 2018

thanks very much . expect you to incorporate the code into the trunk

@TomPallister

This comment has been minimized.

Copy link
Member

@TomPallister TomPallister commented Feb 11, 2018

cool I will merge it soon

@TomPallister

This comment has been minimized.

Copy link
Member

@TomPallister TomPallister commented Feb 13, 2018

This functionality is in version 3.0.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.