The DelegatingHandler inherit from HttpMessageHandler. But, I didn't understand the difference, given that you must implement the same method, SendAsync to make both work.
What's the difference between this two Handlers? When should I use each one?
If you are familiar with ASP.NET, then a good analogy will be HTTP handlers and modules. If you implement an HttpMessageHandler, you implement the Send and SendAsync methods and return a response or promise of a response. This is similar to an Http handler. If you implement a DelegatingHandler and add it to the config.MessageHandlers collection, your class runs in the pipeline and gets an opportunity to see and react to the request and responses, just like an HTTP module. DelegatingHandler is also an HttpMessageHandler except that as part of SendAsync implementation, it just calls the SendAsync of the inner handler. The inner handler will do the same and you get the Chinese boxes or the Russian dolls effect. HttpServer, where the pipeline starts is itself a DelegatingHandler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With