Skip to content

Commit d68fa45

Browse files
committed
Merge branch 'release/v2.0.0'
2 parents b58faac + cb01ee8 commit d68fa45

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "routerify-multipart"
3-
version = "1.1.0"
3+
version = "2.0.0"
44
description = "A multipart/form-data parser for Routerify."
55
homepage = "https://github.com/routerify/routerify-multipart"
66
repository = "https://github.com/routerify/routerify-multipart"
@@ -23,9 +23,9 @@ all = ["json"]
2323
json = ["multer/json"]
2424

2525
[dependencies]
26-
routerify = "1.1"
27-
hyper = "0.13"
28-
multer = "1.2"
26+
routerify = "2"
27+
hyper = "0.14"
28+
multer = "2"
2929

3030
[dev-dependencies]
31-
tokio = { version = "0.2", features = ["full"] }
31+
tokio = { version = "1", features = ["full"] }

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Add this to your `Cargo.toml` file:
1717

1818
```toml
1919
[dependencies]
20-
routerify = "1.1"
21-
routerify-multipart = "1.1"
20+
routerify = "2"
21+
routerify-multipart = "2"
2222
```
2323

2424
## Example

examples/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use routerify_multipart::RequestMultipartExt;
44
use std::net::SocketAddr;
55

66
async fn file_upload_handler(req: Request<Body>) -> Result<Response<Body>, Error> {
7-
let mut multipart = req.into_multipart().map_err(|err| Error::wrap(err))?;
7+
let mut multipart = req.into_multipart().map_err(|err| Error::new(err.to_string()))?;
88

99
while let Some(field) = multipart.next_field().await.map_err(|err| Error::wrap(err))? {
1010
let name = field.name();

src/ext.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
use crate::{Constraints, Multipart};
22
use hyper::{header, Request};
33

4-
/// An extension trait which extends [`hyper::Request<Body>`](https://docs.rs/hyper/0.13.5/hyper/struct.Request.html)
4+
/// An extension trait which extends [`hyper::Request<Body>`](https://docs.rs/hyper/0.14.7/hyper/struct.Request.html)
55
/// to add some methods to parse request body as `multipart/form-data`.
66
pub trait RequestMultipartExt {
77
/// Convert the request body to [`Multipart`](./struct.Multipart.html) if the `content-type` is `multipart/form-data`.
88
///
99
/// # Errors
1010
///
1111
/// This method fails if the request body is not `multipart/form-data` and in this case, you could send a `400 Bad Request` status.
12-
fn into_multipart(self) -> routerify::Result<Multipart>;
12+
fn into_multipart(self) -> routerify::Result<Multipart<'static>>;
1313

1414
/// Convert the request body to [`Multipart`](./struct.Multipart.html) if the `content-type` is `multipart/form-data` with some [constraints](./struct.Constraints.html).
1515
///
1616
/// # Errors
1717
///
1818
/// This method fails if the request body is not `multipart/form-data` and in this case, you could send a `400 Bad Request` status.
19-
fn into_multipart_with_constraints(self, constraints: Constraints) -> routerify::Result<Multipart>;
19+
fn into_multipart_with_constraints(self, constraints: Constraints) -> routerify::Result<Multipart<'static>>;
2020
}
2121

2222
impl RequestMultipartExt for Request<hyper::Body> {
23-
fn into_multipart(self) -> routerify::Result<Multipart> {
23+
fn into_multipart(self) -> routerify::Result<Multipart<'static>> {
2424
let boundary = self
2525
.headers()
2626
.get(header::CONTENT_TYPE)
@@ -30,21 +30,25 @@ impl RequestMultipartExt for Request<hyper::Body> {
3030
if let Some(boundary) = boundary {
3131
Ok(Multipart::new(self.into_body(), boundary))
3232
} else {
33-
Err(routerify::Error::new("Content-Type is not multipart/form-data"))
33+
Err(Box::new(routerify::Error::new(
34+
"Content-Type is not multipart/form-data",
35+
)))
3436
}
3537
}
3638

37-
fn into_multipart_with_constraints(self, constraints: Constraints) -> routerify::Result<Multipart> {
39+
fn into_multipart_with_constraints(self, constraints: Constraints) -> routerify::Result<Multipart<'static>> {
3840
let boundary = self
3941
.headers()
4042
.get(header::CONTENT_TYPE)
4143
.and_then(|val| val.to_str().ok())
4244
.and_then(|val| multer::parse_boundary(val).ok());
4345

4446
if let Some(boundary) = boundary {
45-
Ok(Multipart::new_with_constraints(self.into_body(), boundary, constraints))
47+
Ok(Multipart::with_constraints(self.into_body(), boundary, constraints))
4648
} else {
47-
Err(routerify::Error::new("Content-Type is not multipart/form-data"))
49+
Err(Box::new(routerify::Error::new(
50+
"Content-Type is not multipart/form-data",
51+
)))
4852
}
4953
}
5054
}

0 commit comments

Comments
 (0)