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
Closed

I have a little suggestion about httpclient #208

jakey188 opened this issue Jan 29, 2018 · 10 comments
Labels
feature A new feature medium effort Likely a few days of development effort question Initially seen a question could become a new feature or bug or closed ;)

Comments

@jakey188
Copy link

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
Copy link
Member

@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.

@TomPallister TomPallister added the question Initially seen a question could become a new feature or bug or closed ;) label Jan 29, 2018
@jakey188
Copy link
Author

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
Copy link
Author

I need http tracing . including all services and ocelot

@TomPallister
Copy link
Member

@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?

@TomPallister TomPallister added feature A new feature medium effort Likely a few days of development effort labels Jan 31, 2018
@jakey188
Copy link
Author

jakey188 commented Feb 1, 2018

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

@geffzhang
Copy link
Contributor

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
Copy link
Member

@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
Copy link
Author

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

@TomPallister
Copy link
Member

cool I will merge it soon

@TomPallister
Copy link
Member

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
Labels
feature A new feature medium effort Likely a few days of development effort question Initially seen a question could become a new feature or bug or closed ;)
Projects
None yet
Development

No branches or pull requests

3 participants