Comments (5)
Currently, a Data can be only created from inside rocket. This has some restrictions. In my particular case, I cannot read part of the data and then wrap the rest in another Data object. This pattern is, however, needed by many protocols that built ontop of HTTP and have their own "header+payload" structure within the HTTP body (in my case, it's the IPP protocol).
This is very much on purpose. What we want to guarantee is that any Data
is valid and generated from an incoming request. This is particular important when trying to assert application security properties.
Chainable data guards, as you point out, was indeed designed to solve the kind of problem you illustrate here without giving up the above premise. I believe it should suffice to implement what you're suggesting here. Can you take a look at the api and hash example? The latter takes hash in the prefix of the data body and compares it to a hash of the body itself without copying anywhere.
I would be in favor of a generalized data guard that implements a kind of transformer of the sort you refer to (header + body). Something like:
struct PrefixedData<'r; P: Prefix> {
prefix: P,
data: Data<'r>
}
And make implementing Prefix
as trivial as possible for a variety of usa cases.
from rocket.
Thanks! Took me a bit to understand the API Transformer
provides, but now I think I get it.
It works well with various "push/write" based parsers/transformers such as flate2 's types in the write
module, or as with the hash-example in the repo. Basically everything where you have to push data to yourself. However, I think this API does not work quite as smoothly with read/pull-based ones. In the simplest case, a read-based parser for a "prefix" P
as you wrote above would be a function
pub async fn some_pull_parser(read: &mut impl AsyncRead) -> P {
// do things above to parse the a prefix of "read" into P, by calling the various read.read_..() functions
}
Adapting such a function to the transformer API turns out to be not that easy. While playing with it, my current attempt would be having a transformer that diverts the fresh()
part to an internal buffer from which it can be read using an AsyncRead
impl. Then, once reading the prefix is done, it can go back to just transparently passing the rest of the data downstream.
However, such an approach has several quirks, such as the fact that a transformer is only triggered once the DataStream
is actively read. So, to trigger parsing the prefix, one would have to spawn a background tokio task calling the prefix parser, then peek
one byte of the DataStream or so.
from rocket.
Related Issues (20)
- FileServer can serve pre-gzipped content if it exists on the filesystem HOT 1
- Cookies aren't read by get methods but it exists in the browser HOT 2
- HTTP3/QUIC support HOT 15
- Add HTMLStream HOT 5
- cookie removal and Microsoft Edge HOT 7
- Inject script to auto-reload browser when Rocket restarts HOT 1
- Rocket App Hangs HOT 5
- DefaultListener::bindable() isnβt usable HOT 8
- Allow routes that match any method HOT 4
- Hyper and Rocket disagreeing on validity of URL HOT 3
- Allow from form macro to work on structs with range HOT 4
- Clippy Lint w/ FromForm derive HOT 7
- Possible Incompleteness HOT 1
- Possible Incompleteness HOT 1
- doc: change `&ContentType` with `&Accept` in the list of implementations of `FromRequest` HOT 1
- [Feature]: Enhanced State Mutation for Effortless Handling of Shared Resources HOT 5
- Guide navigation causes relative links inside articles to 404 HOT 1
- Redirection to a route which takes a vector parameter results in an error HOT 1
- Validation not invoked on Json HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rocket.