1
1
use crate :: { Constraints , Multipart } ;
2
2
use hyper:: { header, Request } ;
3
3
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)
5
5
/// to add some methods to parse request body as `multipart/form-data`.
6
6
pub trait RequestMultipartExt {
7
7
/// Convert the request body to [`Multipart`](./struct.Multipart.html) if the `content-type` is `multipart/form-data`.
8
8
///
9
9
/// # Errors
10
10
///
11
11
/// 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 > > ;
13
13
14
14
/// Convert the request body to [`Multipart`](./struct.Multipart.html) if the `content-type` is `multipart/form-data` with some [constraints](./struct.Constraints.html).
15
15
///
16
16
/// # Errors
17
17
///
18
18
/// 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 > > ;
20
20
}
21
21
22
22
impl RequestMultipartExt for Request < hyper:: Body > {
23
- fn into_multipart ( self ) -> routerify:: Result < Multipart > {
23
+ fn into_multipart ( self ) -> routerify:: Result < Multipart < ' static > > {
24
24
let boundary = self
25
25
. headers ( )
26
26
. get ( header:: CONTENT_TYPE )
@@ -30,21 +30,25 @@ impl RequestMultipartExt for Request<hyper::Body> {
30
30
if let Some ( boundary) = boundary {
31
31
Ok ( Multipart :: new ( self . into_body ( ) , boundary) )
32
32
} 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
+ ) ) )
34
36
}
35
37
}
36
38
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 > > {
38
40
let boundary = self
39
41
. headers ( )
40
42
. get ( header:: CONTENT_TYPE )
41
43
. and_then ( |val| val. to_str ( ) . ok ( ) )
42
44
. and_then ( |val| multer:: parse_boundary ( val) . ok ( ) ) ;
43
45
44
46
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) )
46
48
} 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
+ ) ) )
48
52
}
49
53
}
50
54
}
0 commit comments