Closed Ogeon closed 7 years ago
I'm considering replacing send_file_with_mime
, as well, but I haven't decided how.
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!
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+
:pushpin: Commit cc01342 has been approved by Ogeon
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 ofResult
, 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 theResponse
takeResult
s and other types, and let those types set headers and response status. That's the idea behind thisSendResponse
trait.To make some of this possible, the whole handler/router system was turned inside-out, resulting in the removal of
Find
and introduction ofHandleRequest
. 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, makingResponse::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
andtry_send
are changed,send_file
is removed, and the difference between handlers and routers is more or less gone.