UseWebApi and UseHttpMessageHandler doesn't call next OWIN's middleware other than 404

Topics: ASP.NET Web API, General
Aug 11, 2013 at 10:02 AM
OWIN spec says that OWIN middleware's are called in the order they are defined. If I use UseWebApi or UseHttpMessageHandler which in turn use HttpMessageHandlerAdapter, next middleware is not called unless middleware returns 404.

First of all, this is not according to my understanding of OWIN middleware. So if this behaviour correct, please point me to where this behaviour is described.

The problem is, implementing a common "DelegatingHandler" that can be shared among applications and is implemented as an OWIN middleware is impossible by the route of UseWebApi or UseHttpMessageHandler. I am trying to plugin CacheCow as an OWIN middleware and hoped to be able to use UseHttpMessageHandler.

Any ideas?

I believe, there must be a parameter that you could control how "calling next" behaviour is defined, not just by the way of 404.
Aug 11, 2013 at 5:52 PM
aliostad wrote:
OWIN spec says that OWIN middleware's are called in the order they are defined. If I use UseWebApi or UseHttpMessageHandler which in turn use HttpMessageHandlerAdapter, next middleware is not called unless middleware returns 404.

First of all, this is not according to my understanding of OWIN middleware. So if this behaviour correct, please point me to where this behaviour is described.
The standard behaviour of owin middleware is not specifically defined anywhere. It is entirely up to each middle component to decide whether to call the next step in the pipeline or not.
The problem is, implementing a common "DelegatingHandler" that can be shared among applications and is implemented as an OWIN middleware is impossible by the route of UseWebApi or UseHttpMessageHandler. I am trying to plugin CacheCow as an OWIN middleware and hoped to be able to use UseHttpMessageHandler.

Any ideas?

I believe, there must be a parameter that you could control how "calling next" behaviour is defined, not just by the way of 404.
Reasonable request. Nancy does this, for example.
Aug 12, 2013 at 5:22 PM
The problem is, implementing a common "DelegatingHandler" that can be shared among applications and is implemented as an OWIN middleware is impossible by the route of UseWebApi or UseHttpMessageHandler. I am trying to plugin CacheCow as an OWIN middleware and hoped to be able to use UseHttpMessageHandler.
Are you wanting (1) a DelegatingHandler that can directly call Next in the OWIN pipeline? Or are you wanting more flexibility to determine if the OWIN WebApi/HttpMessageHandler adapter should call next after the DelegatingHandler returns some response?

Approach #1 isn't feasible. We tried it, but the cost of going from OWIN->HttpRequestMesage->OWIN, OWIN->HttpResponseMessage->OWIN was prohibitive.

Approach #2 is feasible. As mentioned above, Nancy has a callback you can use to determine which requests flow through. What are you trying to do where the 404 "this request was not handled by WebApi" approach doesn't work?
Aug 12, 2013 at 9:24 PM
@Tratcher Thanks. Yes, it is possible and in fact I have already done it. I was about to send a PR but if you plan to fix it soon can wait for your impl. My impl usesFunc<HttpRequestMessage, HttpResponseMessage, bool> as the callNextPolicy.

Now going back to the issue #1. Is this the best place to discuss it or your prefer discussing in OWIN mailing list?
Aug 12, 2013 at 9:51 PM
Take it to the mailing list, they're familiar with the issue.