Ogeon / rustful

[OUTDATED] A light HTTP framework for Rust
https://docs.rs/rustful
Apache License 2.0
862 stars 51 forks source link

Add a SendResponse trait and restructure the router system #121

Closed Ogeon closed 7 years ago

Ogeon commented 8 years ago

The idea was born after I got a request for a good way to use try!. My first thought was to find a way to make a handler return some kind of Result, which would be tricky and probably require specialization for it to be ergonomic. After letting it rest for a few days I realized that I could still get quite close by making the Response take Results and other types, and let those types set headers and response status. That's the idea behind this SendResponse trait.

To make some of this possible, the whole handler/router system was turned inside-out, resulting in the removal of Find and introduction of HandleRequest. An upside is that handler composition is more powerful, while a downside is that the compiler can't always infer the router type. The extra explicitness should hopefully not be too bad, though.

A bonus effect is that the returned error from Response::send can be customized, making Response::send_file obsolete.

Closes #109, closes #98 (HandleRequest can do that now).

This is a breaking change, since the input parameters and return values of send and try_send are changed, send_file is removed, and the difference between handlers and routers is more or less gone.

Ogeon commented 8 years ago

I'm considering replacing send_file_with_mime, as well, but I haven't decided how.

Ogeon commented 7 years ago

While most of my time and energy has been spent on work and making my new place look like a real home, I have kept working on this whenever the necessary planets have aligned. I gave it a more serious go yesterday and did finally manage to turn the router system inside-out to make it easier to have more customized handlers. There are still a bunch of things to fix before pushing, and I'm having a bit of trouble with type inference, but it's taking shape. It's at least not abandoned. It never was!

Ogeon commented 7 years ago

I'm considering this "done" even if there is room for general improvements. The next step is to see if I can make the router building situation better.

Let's see if this still works...

@homu r+

homu commented 7 years ago

:pushpin: Commit cc01342 has been approved by Ogeon

homu commented 7 years ago

:zap: Test exempted - status