http-rs / tide

Fast and friendly HTTP server framework for async Rust
https://docs.rs/tide
Apache License 2.0
5.06k stars 321 forks source link

not possible to remove standard middleware when using Server::with_state() #476

Open leonbreedt opened 4 years ago

leonbreedt commented 4 years ago

In my case, I use Server::with_state(), which means I get the standard LogMiddleware.

However, I have a custom logging middleware to add more context for request logging (method, path, etc as structured arguments instead of a formatted string).

So I get doubled up log entries.

It feels like deciding to have state (DB pool in my case) and getting default middleware should be separate decisions, like with_logging(), with_cookies()?

vladan commented 4 years ago

Hi @leonbreedt, I've submitted a PR for another issue regarding the default logging / cookies in nested servers in https://github.com/http-rs/tide/pull/468, but like your proposition for with_logging() and with_cookies() better :)

IMHO it would be good to have them completely out of the server creation and use them as a builder Server::with_state(...).with_logger().with_cookies(), or maybe even:

    let app = tide::new()
    .with_state(...)
    .with_logging()
    .with_cookies()

which would solve both of our problems :)