@@ -18,6 +18,7 @@ use anyhow::{bail, Context};
18
18
use bytes:: { Buf , Bytes } ;
19
19
use headers:: { ContentType , HeaderMapExt } ;
20
20
use http:: { header:: ACCEPT , HeaderValue , Request , Response , StatusCode } ;
21
+ use http_body_util:: { BodyExt , Empty } ;
21
22
use mas_http:: {
22
23
BodyToBytesResponseLayer , BytesToBodyRequestLayer , CatchHttpCodesLayer ,
23
24
FormUrlencodedRequestLayer , JsonRequestLayer , JsonResponseLayer ,
@@ -51,7 +52,7 @@ async fn test_http_errors() {
51
52
) ;
52
53
let svc = layer. layer ( service_fn ( handle) ) ;
53
54
54
- let request = Request :: new ( hyper :: Body :: empty ( ) ) ;
55
+ let request = Request :: new ( Empty :: < Bytes > :: new ( ) ) ;
55
56
56
57
let res = svc. oneshot ( request) . await ;
57
58
let err = res. expect_err ( "the request should fail" ) ;
@@ -60,7 +61,7 @@ async fn test_http_errors() {
60
61
61
62
#[ tokio:: test]
62
63
async fn test_json_request_body ( ) {
63
- async fn handle < B > ( request : Request < B > ) -> Result < Response < hyper :: Body > , anyhow:: Error >
64
+ async fn handle < B > ( request : Request < B > ) -> Result < Response < Empty < Bytes > > , anyhow:: Error >
64
65
where
65
66
B : http_body:: Body + Send ,
66
67
B :: Error : std:: error:: Error + Send + Sync + ' static ,
@@ -74,12 +75,12 @@ async fn test_json_request_body() {
74
75
bail ! ( "Content-Type header is not application/json" )
75
76
}
76
77
77
- let bytes = hyper :: body :: to_bytes ( request. into_body ( ) ) . await ?;
78
+ let bytes = request. into_body ( ) . collect ( ) . await ?. to_bytes ( ) ;
78
79
if bytes. to_vec ( ) != br#"{"hello":"world"}"# . to_vec ( ) {
79
80
bail ! ( "Body mismatch" )
80
81
}
81
82
82
- let res = Response :: new ( hyper :: Body :: empty ( ) ) ;
83
+ let res = Response :: new ( Empty :: new ( ) ) ;
83
84
Ok ( res)
84
85
}
85
86
@@ -111,7 +112,7 @@ async fn test_json_response_body() {
111
112
let layer = ( JsonResponseLayer :: default ( ) , BodyToBytesResponseLayer ) ;
112
113
let svc = layer. layer ( service_fn ( handle) ) ;
113
114
114
- let request = Request :: new ( hyper :: Body :: empty ( ) ) ;
115
+ let request = Request :: new ( Empty :: < Bytes > :: new ( ) ) ;
115
116
116
117
let res = svc. oneshot ( request) . await ;
117
118
let response = res. expect ( "the request to succeed" ) ;
@@ -121,7 +122,7 @@ async fn test_json_response_body() {
121
122
122
123
#[ tokio:: test]
123
124
async fn test_urlencoded_request_body ( ) {
124
- async fn handle < B > ( request : Request < B > ) -> Result < Response < hyper :: Body > , anyhow:: Error >
125
+ async fn handle < B > ( request : Request < B > ) -> Result < Response < Empty < Bytes > > , anyhow:: Error >
125
126
where
126
127
B : http_body:: Body + Send ,
127
128
B :: Error : std:: error:: Error + Send + Sync + ' static ,
@@ -135,10 +136,10 @@ async fn test_urlencoded_request_body() {
135
136
bail ! ( "Content-Type header is not application/x-form-urlencoded" )
136
137
}
137
138
138
- let bytes = hyper :: body :: to_bytes ( request. into_body ( ) ) . await ?;
139
+ let bytes = request. into_body ( ) . collect ( ) . await ?. to_bytes ( ) ;
139
140
assert_eq ! ( bytes. to_vec( ) , br"hello=world" . to_vec( ) ) ;
140
141
141
- let res = Response :: new ( hyper :: Body :: empty ( ) ) ;
142
+ let res = Response :: new ( Empty :: new ( ) ) ;
142
143
Ok ( res)
143
144
}
144
145
0 commit comments