c-cube / tiny_httpd

Minimal HTTP server using good old threads + blocking IO, with a small request router.
https://c-cube.github.io/tiny_httpd
75 stars 11 forks source link

Middleware and accept overlap a bit ? Need more freedom for composition ? #51

Closed craff closed 7 months ago

craff commented 1 year ago
c-cube commented 1 year ago

Yes, accept predates middlewares, it's a bit redundant. However it's also simpler to use for basic cases, I think.

Middlewares can already look at the request first, or modify the response last. They can't modify the response first because it simply doesn't exist before the inner layer returns a response. An example of middleware that modifies both request and response is the camlzip middleware. How it works: the middleware takes handler and req and resp (a continuation that will eat the response); it can modify req before passing it to handler if needed; it can intercept the response from the handler before passing it to resp.

Composition operators on middlewares is clearly a possibility, but the question is: what more than the list do you need? Choice? I'm open to the idea but I think it'd be good to have concrete examples of use cases.

c-cube commented 7 months ago

I think the overlap is fine for now.