@@ -1048,6 +1048,24 @@ fn append_allow_header(allow_header: &mut AllowHeader, method: &'static str) {
1048
1048
}
1049
1049
}
1050
1050
1051
+ impl < B , E > Service < Request < B > > for MethodRouter < ( ) , B , E >
1052
+ where
1053
+ B : HttpBody ,
1054
+ {
1055
+ type Response = Response ;
1056
+ type Error = E ;
1057
+ type Future = RouteFuture < B , E > ;
1058
+
1059
+ #[ inline]
1060
+ fn poll_ready ( & mut self , _cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , Self :: Error > > {
1061
+ Poll :: Ready ( Ok ( ( ) ) )
1062
+ }
1063
+
1064
+ fn call ( & mut self , req : Request < B > ) -> Self :: Future {
1065
+ self . clone ( ) . with_state ( ( ) ) . call ( req)
1066
+ }
1067
+ }
1068
+
1051
1069
impl < S , B , E > Clone for MethodRouter < S , B , E > {
1052
1070
fn clone ( & self ) -> Self {
1053
1071
Self {
@@ -1207,6 +1225,19 @@ mod tests {
1207
1225
assert ! ( body. is_empty( ) ) ;
1208
1226
}
1209
1227
1228
+ #[ tokio:: test]
1229
+ async fn get_service_fn ( ) {
1230
+ async fn handle ( _req : Request < Body > ) -> Result < Response < Body > , Infallible > {
1231
+ Ok ( Response :: new ( Body :: from ( "ok" ) ) )
1232
+ }
1233
+
1234
+ let mut svc = get_service ( service_fn ( handle) ) ;
1235
+
1236
+ let ( status, _, body) = call ( Method :: GET , & mut svc) . await ;
1237
+ assert_eq ! ( status, StatusCode :: OK ) ;
1238
+ assert_eq ! ( body, "ok" ) ;
1239
+ }
1240
+
1210
1241
#[ tokio:: test]
1211
1242
async fn get_handler ( ) {
1212
1243
let mut svc = MethodRouter :: new ( ) . get ( ok) . with_state ( ( ) ) ;
0 commit comments