1
- use axum:: {
2
- body:: { self , BoxBody } ,
3
- response:: Response ,
4
- BoxError ,
5
- } ;
1
+ use axum:: { body, response:: Response , BoxError } ;
6
2
use bytes:: Bytes ;
7
3
use casbin:: prelude:: { TryIntoAdapter , TryIntoModel } ;
8
4
use casbin:: { CachedEnforcer , CoreApi , Result as CasbinResult } ;
9
5
use futures:: future:: BoxFuture ;
10
6
use http:: { Request , StatusCode } ;
11
- use http_body:: { Body as HttpBody , Full } ;
7
+ use http_body:: Body as HttpBody ;
8
+ use http_body_util:: Full ;
12
9
use std:: {
13
10
convert:: Infallible ,
14
11
ops:: { Deref , DerefMut } ,
93
90
ResBody : HttpBody < Data = Bytes > + Send + ' static ,
94
91
ResBody :: Error : Into < BoxError > ,
95
92
{
96
- type Response = Response < BoxBody > ;
93
+ type Response = Response ;
97
94
type Error = Infallible ;
98
95
// `BoxFuture` is a type alias for `Pin<Box<dyn Future + Send + 'a>>`
99
96
type Future = BoxFuture < ' static , Result < Self :: Response , Self :: Error > > ;
@@ -116,7 +113,7 @@ where
116
113
None => {
117
114
return Ok ( Response :: builder ( )
118
115
. status ( StatusCode :: UNAUTHORIZED )
119
- . body ( body:: boxed ( Full :: from ( "401 Unauthorized" ) ) )
116
+ . body ( body:: Body :: new ( Full :: from ( "401 Unauthorized" ) ) )
120
117
. unwrap ( ) ) ;
121
118
}
122
119
} ;
@@ -129,20 +126,20 @@ where
129
126
match lock. enforce_mut ( vec ! [ subject, domain, path, action] ) {
130
127
Ok ( true ) => {
131
128
drop ( lock) ;
132
- Ok ( inner. call ( req) . await ?. map ( body:: boxed ) )
129
+ Ok ( inner. call ( req) . await ?. map ( body:: Body :: new ) )
133
130
}
134
131
Ok ( false ) => {
135
132
drop ( lock) ;
136
133
Ok ( Response :: builder ( )
137
134
. status ( StatusCode :: FORBIDDEN )
138
- . body ( body:: boxed ( Full :: from ( "403 Forbidden" ) ) )
135
+ . body ( body:: Body :: new ( Full :: from ( "403 Forbidden" ) ) )
139
136
. unwrap ( ) )
140
137
}
141
138
Err ( _) => {
142
139
drop ( lock) ;
143
140
Ok ( Response :: builder ( )
144
141
. status ( StatusCode :: BAD_GATEWAY )
145
- . body ( body:: boxed ( Full :: from ( "502 Bad Gateway" ) ) )
142
+ . body ( body:: Body :: new ( Full :: from ( "502 Bad Gateway" ) ) )
146
143
. unwrap ( ) )
147
144
}
148
145
}
@@ -151,28 +148,28 @@ where
151
148
match lock. enforce_mut ( vec ! [ subject, path, action] ) {
152
149
Ok ( true ) => {
153
150
drop ( lock) ;
154
- Ok ( inner. call ( req) . await ?. map ( body:: boxed ) )
151
+ Ok ( inner. call ( req) . await ?. map ( body:: Body :: new ) )
155
152
}
156
153
Ok ( false ) => {
157
154
drop ( lock) ;
158
155
Ok ( Response :: builder ( )
159
156
. status ( StatusCode :: FORBIDDEN )
160
- . body ( body:: boxed ( Full :: from ( "403 Forbidden" ) ) )
157
+ . body ( body:: Body :: new ( Full :: from ( "403 Forbidden" ) ) )
161
158
. unwrap ( ) )
162
159
}
163
160
Err ( _) => {
164
161
drop ( lock) ;
165
162
Ok ( Response :: builder ( )
166
163
. status ( StatusCode :: BAD_GATEWAY )
167
- . body ( body:: boxed ( Full :: from ( "502 Bad Gateway" ) ) )
164
+ . body ( body:: Body :: new ( Full :: from ( "502 Bad Gateway" ) ) )
168
165
. unwrap ( ) )
169
166
}
170
167
}
171
168
}
172
169
} else {
173
170
Ok ( Response :: builder ( )
174
171
. status ( StatusCode :: UNAUTHORIZED )
175
- . body ( body:: boxed ( Full :: from ( "401 Unauthorized" ) ) )
172
+ . body ( body:: Body :: new ( Full :: from ( "401 Unauthorized" ) ) )
176
173
. unwrap ( ) )
177
174
}
178
175
} )
0 commit comments