1- use std:: future:: Future ;
2-
3- use actix_web:: body:: BoxBody ;
1+ use actix_web:: body:: MessageBody ;
42use actix_web:: dev:: { Service , ServiceRequest , ServiceResponse } ;
5- use actix_web:: http:: header:: HeaderName ;
63use actix_web:: http:: Method ;
4+ use actix_web:: http:: header:: HeaderName ;
75use actix_web:: web;
6+ use futures_util:: future:: LocalBoxFuture ;
87
98use crate :: IntelMission ;
109
11- pub fn queue_length < S > (
10+ pub fn queue_length < S , B > (
1211 req : ServiceRequest ,
1312 srv : & S ,
14- ) -> impl Future < Output = Result < ServiceResponse , actix_web:: Error > >
13+ ) -> LocalBoxFuture < ' static , Result < ServiceResponse < B > , actix_web:: Error > >
1514where
16- S : Service < ServiceRequest , Response = ServiceResponse < BoxBody > , Error = actix_web:: Error > ,
15+ S : Service < ServiceRequest , Response = ServiceResponse < B > , Error = actix_web:: Error > ,
16+ S :: Future : ' static ,
17+ B : MessageBody + ' static ,
1718{
1819 let length = ( req. method ( ) == Method :: GET ) . then ( || {
1920 let mission = req
@@ -23,19 +24,18 @@ where
2324 mission. metrics . task_in_queue . get ( )
2425 } ) ;
2526 let fut = srv. call ( req) ;
26- async move {
27- let mut resp: ServiceResponse < _ > = fut. await ?;
27+
28+ Box :: pin ( async move {
29+ let mut resp = fut. await ?;
2830 if let Some ( length) = length {
2931 // Rewrite the response to return the current counts.
3032 resp. headers_mut ( ) . append (
3133 HeaderName :: from_static ( "x-intel-queue-length" ) ,
3234 length. into ( ) ,
3335 ) ;
34- return Ok ( resp) ;
3536 }
36-
3737 Ok ( resp)
38- }
38+ } )
3939}
4040
4141#[ cfg( test) ]
@@ -44,13 +44,13 @@ mod tests {
4444
4545 use actix_http:: Request ;
4646 use actix_web:: dev:: { Service , ServiceResponse } ;
47- use actix_web:: test:: { call_service , init_service , TestRequest } ;
48- use actix_web:: { web , App } ;
47+ use actix_web:: test:: { TestRequest , call_service , init_service } ;
48+ use actix_web:: { App , web } ;
4949 use reqwest:: Client ;
5050
5151 use crate :: common:: S3Config ;
5252 use crate :: storage:: get_anonymous_s3_client;
53- use crate :: { queue_length , IntelMission , Metrics } ;
53+ use crate :: { IntelMission , Metrics , queue_length } ;
5454
5555 async fn make_service (
5656 metrics : Arc < Metrics > ,
0 commit comments