Multipart only consumes payload in extractor after header checks.
Payload is always consumed preventing optional extraction.
Perform header checks in FromRequest to prevent always calling payload.take()
Precedent set with web::Json extraction. It receives a &mut Payload and does not modify it until header content type checks passed.
Hi @robjtede I took a stab at this.
I ended up with an implementation for FromRequest that looks like this:
impl FromRequest for Multipart {
type Error = Error;
type Future = Ready<Result<Multipart, Error>>;
type Config = ();
#[inline]
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
ok(match Multipart::boundary(req.headers()) {
Ok(boundary) => Multipart::from_boundary_stream(boundary, payload.take()),
Err(err) => Multipart::from_error(err),
})
}
}
The idea is to add two new methods 馃槵
Also we make the boundary, from_boundary_stream, from_error methods public within the crate so that we can use them in the extractor.
_PS: from_boundary_stream name kinda falls short, open to better names_
_I would like feedback on this approach, if it makes sense I'll submit a fully fledged PR_
Maybe just from_boundary. Just my two cents.