-
Notifications
You must be signed in to change notification settings - Fork 1
Upstream communication
The OWIN pipeline is a chain of methods with the Func<Task> signature. When a request is received it is passed down this chain until a middleware class chooses to handle the request. It is easy to see how middleware that runs earlier in the chain can pass information down to middleware that runs later (this is downstream communication) but how can middleware that runs later alter the behaviour of middleware that ran before it?
Take the example of session. If is is expensive to establish a session because it contains lots of data and it is stored in a database for example, and session is not always required (maybe the request is for a jpg image where session plays no part),then we want to avoid loading up session where it's not needed, but the middleware that knows if session is needed or not runs after the session middleware. How can we solve this problem?
The solution lies in the fact that the OWIN Framework has a routing phase and a request processing phase. During the routing phase middleware components figure out how they are going to handle the request, then in the second phase the response is produced and sent back to the browser. During the routing phase downstream components can pass information to upstream components (such as whether session is required) before the second phase starts. This is referred to as upstream communication.