use axum::{
    Json,
    response::{IntoResponse, Response},
    body::Body,
    http::StatusCode,
};

struct ConfigState {
    captcha_key: String,
}

async fn captcha_middleware(
    State(state): State<ConfigState>,
    // you can add more extractors here but the last
    // extractor must implement `FromRequest` which
    // `Request` does
    request: Request,
    next: Next,
) -> Response {
    //TODO: check captcha
    let is_captcha_valid = true;
    
    if is_captcha_valid {
        let response = next.run(request).await;
        response
    }
    Response::builder()
        .status(StatusCode::FORBIDDEN)
        .body(Body::from("Wrong captcha"))

}

fn main() {

}

Изменить пасту