Ogeon / rustful

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

Preserve non-UTF-8 data and handle * requests #59

Closed Ogeon closed 9 years ago

Ogeon commented 9 years ago

This makes the server avoid destroying any non-UTF-8 data from the requests. This is done by packaging the data as either a Vec<u8> or a String in a MaybeUtf8 type and only ruin the non-UTF-8 data if the user asks for it.

The Parameters type has been further specialized and extended to make things more convenient, through an extra layer of conversion back and forth between types. It has also been moved into the context module, which has been divided into sub modules to keep things organized.

The only place where losslessness has been sacrificed for convenience is in the get in Parameters. It will perform a conversion if the parameter value is non-UTF-8 data, but there is also a get_raw for when the original data is desired. I hope it won't become too much of a footgun, but I suspect that most people want strings instead of bytes.

All this was triggered by the first commit, where * request are finally handled. They will be redirected to the fallback handler and the path field in Context has been replaced by a uri field with a new Uri type, that can represent * URIs as well as lossless paths. This shouldn't be too inconvenient.

A side effect of the desire to preserve the data is that the Router trait and friends had to be changed. It's really some hairy business and I managed to bork the compiler into forgetting that String implements traits a couple of times :confounded:

This pull request is quite monolithic and definitely breaking.

Ogeon commented 9 years ago

I think this is all for this PR, unless I happen to have missed something. This is such a big change so it's completely possible.

Ogeon commented 9 years ago

@homu r+

homu commented 9 years ago

:pushpin: Commit 4eea3eb has been approved by Ogeon

homu commented 9 years ago

:hourglass: Testing commit 4eea3eb with merge 258a0c7...

homu commented 9 years ago

:broken_heart: Test failed - status

Ogeon commented 9 years ago

@homu retry

homu commented 9 years ago

:hourglass: Testing commit 4eea3eb with merge 44e3bf6...

homu commented 9 years ago

:sunny: Test successful - status