Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpMessageHandler vs DelegatingHandler

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?

like image 459
Fals Avatar asked Sep 06 '13 18:09

Fals


1 Answers

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.

like image 75
Badri Avatar answered Oct 11 '22 08:10

Badri