Expand description
Support for multipart/form-data bodies in Nickel via the
multipart crate.
§Why an external crate?
Three major reasons led to the decision to move Nickel integration to an external crate.
1: The part of Nickel’s public API that matters to multipart (getting headers and
reading the request) uses Hyper’s request type; this means that Nickel’s integration
must necessarily be coupled to Hyper’s integration.
2: Cargo does not allow specifying two different versions of the same crate in the same manifest, probably for some good reasons but this crate’s author has not looked into it.
3: Nickel’s development moves incredibly slowly; when a new version of Hyper releases, there is always a significant lag before Nickel upgrades, sometimes several months–in this case, Hyper was upgraded (in May) two months before the issue was opened (July), but a new version of Nickel was not published until four months later (September).
This causes problems for multipart because it cannot upgrade Hyper until Nickel does,
but its Hyper users often want to upgrade their Hyper as soon as possible.
In order to provide up-to-date integration for Hyper, it was necessary to move Nickel
integration to an external crate so it can be pinned at the version of Hyper that Nickel
supports. This allows multipart to upgrade Hyper arbitrarily and still keep everyone happy.
§Porting from multipart’s Integration
Whereas multipart only provided one way to wrap a Nickel request, this crate provides two:
- To continue using
Multipart::from_request(), wrap the request inMaybe:
// Where `req` is `&mut nickel::Request`
- Multipart::from_request(req)
+ use multipart_nickel::Maybe;
+ Multipart::from_request(Maybe(req))- Import
multipart_nickel::MultipartBodyand call.multipart_body(), which returnsOption(which better matches the conventions ofnickel::FormBodyandnickel::JsonBody):
use multipart_nickel::MultipartBody;
// Where `req` is `&mut nickel::Request`
match req.multipart_body() {
Some(multipart) => // handle multipart body
None => // handle regular body
}This crate also reexports the server module from the version of multipart
that it uses, so that you don’t have to import multipart separately.
Modules§
- multipart_
server - The
servermodule from the version ofmultipartthat this crate uses. The server-side abstraction for multipart requests. Enabled with theserverfeature.
Structs§
- Maybe
- A wrapper for
&mut nickel::Requestwhich implementsmultipart::server::HttpRequest.
Traits§
- Multipart
Body - Extension trait for getting the
multipart/form-databody fromnickel::Request.