Crate multipart_nickel [] [src]

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 in Maybe:
Be careful when using this code, it's not being tested!
// Where `req` is `&mut nickel::Request`
- Multipart::from_request(req)
+ use multipart_nickel::Maybe;
+ Multipart::from_request(Maybe(req))
  • Import multipart_nickel::MultipartBody and call .multipart_body(), which returns Option (which better matches the conventions of nickel::FormBody and nickel::JsonBody):
Be careful when using this code, it's not being tested!
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 server-side abstraction for multipart requests. Enabled with the server feature.

Structs

Maybe

A wrapper for &mut nickel::Request which implements multipart::server::HttpRequest.

Traits

MultipartBody

Extension trait for getting the multipart/form-data body from nickel::Request.