vibe-d / vibe.d

Official vibe.d development
MIT License
1.15k stars 284 forks source link

Stacking http handlers #1305

Open jkm opened 9 years ago

jkm commented 9 years ago

I need to set some headers to control caching of a web site. What's the recommended way to do this? I'm thinking about stacking the requests, e.g., the server request is first handled by function a, next it is handled by function b, etc. In essence I want the flexibility of Rack.

How would you go about that?

dariusc93 commented 9 years ago

I assume you are referring to middleware? There is a basic form of implementing middleware with the webinterface and possible restinterface but i do not find that to be a very clean implementation. Refer to https://github.com/rejectedsoftware/vibe.d/blob/master/examples/web/source/app.d#L54 .

jkm commented 9 years ago

Yes. In Rack they call these units of functionality middleware. I want to build flexible flows. I think it also the applies to non-web stuff. I used to work with the click modular router. There you have a similar concept. Each block does a specific unit of work on packets and you just configure the packet processing on top using these basic elements. From the link I cannot tell how that relates to this here. But it may go in the direction I need it. I think this would extend vibe's applications enormously and lead to simpler code.

landaire commented 9 years ago

Adding on to this discussion I think this would be very useful. If it is currently possible then some examples would be awesome. My use case would be for example logging requests. If I want to print to std(out|err) in dev then having some handler that's called before and after each request and logs information about it would be great, but I currently don't see an easy way of doing this without maybe extending the router.