/// Routes `req` to the appropriate handler, if any, returning the handler
/// response.
Routes `req` to the appropriate handler, if any, returning the handler
response.
Routes ` req ` to the appropriate handler if any returning the handler response .
pub async fn route(&self, req: Request<Body>) -> Result<Response<Body>, Error> {
        // Acquire and hold a permit for the duration of this request, or return
        // a 503 if the existing requests have already exhausted the allocation.
        //
        // By dropping requests at the routing stage, before the request buffer
        // is read/decompressed, this limit can efficiently shed load to avoid
        // unnecessary memory pressure (the resource this request limit usually
        // aims to protect.)
        let _permit = match self.request_sem.try_acquire() {
            Ok(p) => p,
            Err(TryAcquireError::NoPermits) => {
                error!("simultaneous request limit exceeded - dropping request");
                self.request_limit_rejected.inc(1);
                return Err(Error::RequestLimit);
            }
            Err(e) => panic!("request limiter error: {}", e),
        };
        // Route the request to a handler.
        match (req.method(), req.uri().path()) {
            (&Method::POST, "/api/v2/write") => self.write_handler(req).await,
            (&Method::POST, "/api/v2/delete") => self.delete_handler(req).await,
            _ => return Err(Error::NoHandler),
        }
        .map(|summary| {
            Response::builder()
                .status(StatusCode::NO_CONTENT)
                .header(WRITE_TOKEN_HTTP_HEADER, summary.to_token())
                .body(Body::empty())
                .unwrap()
        })
    }
pub async fn route ( & self , req : Request < Body > ) -> Result < Response < Body > , Error > { // Acquire and hold a permit for the duration of this request, or return // a 503 if the existing requests have already exhausted the allocation. // // By dropping requests at the routing stage, before the request buffer // is read/decompressed, this limit can efficiently shed load to avoid // unnecessary memory pressure (the resource this request limit usually // aims to protect.) let _permit = match self . request_sem . try_acquire ( ) { Ok ( p ) => p , Err ( TryAcquireError :: NoPermits ) => { error ! ( " " ) ; self . request_limit_rejected . inc ( 1 ) ; return Err ( Error :: RequestLimit ) ; } Err ( e ) => panic ! ( " " e ) , } ; // Route the request to a handler. match ( req . method ( ) , req . uri ( ) . path ( ) ) { ( & Method :: POST , " " ) => self . write_handler ( req ) . await , ( & Method :: POST , " " ) => self . delete_handler ( req ) . await , _ => return Err ( Error :: NoHandler ) , } . map ( | summary | { Response :: builder ( ) . status ( StatusCode :: NO_CONTENT ) . header ( WRITE_TOKEN_HTTP_HEADER , summary . to_token ( ) ) . body ( Body :: empty ( ) ) . unwrap ( ) } ) }
Routes `req` to the appropriate handler, if any, returning the handler
response.
Routes ` req ` to the appropriate handler if any returning the handler response .
&self
req
Request<Body>