Help with tokio_fastcgi Library

Hi.

I would like to create a health probe server for FCGI Programs.
I try to use the GitHub - FlashSystems/tokio-fastcgi: Async FastCGI handler library for Tokio.rs library for the FCGI Part and struggle now with that line.

    let mut requests = Requests::from_split_socket(dest_connection, 10, 10);

As you can see in the code below can I listen to the HTTP Socket and when the request is done with curl -v http://127.0.0.1:8080/fcgi-ping should the server ask the FCGI Daemon for /fpm-ping.

The examples are all with accept() but not with connect().
Please can you help me to solve the question how to make a call with a client connection and where can I set the /fpm-ping Path in the Library?

Thank you for your help.

Here is the full code.

use axum::{
    extract::Request,
    http::{header, header::HeaderName, HeaderMap, StatusCode},
    routing::get,
    Router,
    response::{IntoResponse, Response, Result},
};
use std::{
    env, future::Future, net::{SocketAddr, ToSocketAddrs}
};
use tokio::{io::{AsyncReadExt, AsyncWriteExt}, net::{TcpListener, TcpStream}};
use tokio_fastcgi::{RequestResult, Requests};
//use tokio::io::{AsyncReadExt, AsyncWriteExt};

const DEFAULT_DEST_PORT: u16 = 9000;

async fn hello_world() -> &'static str {
    "Hello world!"
}

async fn check_fcgi_endpoint(headers: HeaderMap, req: Request) -> Result<(), StatusCode> {
    println!("Request Headers {:?}", headers);
    println!("Request {:?}", req);
    println!("Request URI :{:?}:", req.uri());

    let destination_addr =
        env::var("DESTINATION").expect("Define DESTINATION=host in your env");

    let destination_port = env::var("DESTINATION_PORT")
        .ok()
        .and_then(|destination_port| destination_port.parse::<u16>().ok())
        .unwrap_or(DEFAULT_DEST_PORT);

    println!("Dest to addr {}", destination_addr);
    println!("Dest to port {}", destination_port);

    let php_addr = (destination_addr, destination_port)
        .to_socket_addrs()
        .expect("Unable to resolve the IP address")
        .next()
        .expect("DNS resolution returned no IP addresses");

    //let dest_connection = TcpStream::connect(&php_addr).await.expect("msg");
    let mut dest_connection = match TcpStream::connect(&php_addr).await{
        Ok(dest_connection) => dest_connection,
        Err(e) => panic!("{}", e),
    };


    println!("Dest to conn {:?}", dest_connection);

     # Need help with this line
    let mut requests = Requests::from_split_socket(dest_connection, 10, 10);

    //Ok("From check_fcgi_endpoint\n")
    Ok(())

}

#[tokio::main]
async fn main() {
    // initialize tracing
    tracing_subscriber::fmt::init();

    let server_addr = env::var("SERVER").expect("Define SERVER=host:port in your env");

    let router = Router::new()
        .route("/", get(hello_world))
        .route("/fcgi-ping", get(check_fcgi_endpoint));

    println!("Listening on {}", server_addr);

    let tcp = TcpListener::bind(&server_addr).await.unwrap();

    axum::serve(tcp, router).await.unwrap();
}

FYI: I have also create a issue at GH Use `Requests::new` or `Requests::from_split_socket` · Issue #5 · FlashSystems/tokio-fastcgi · GitHub

I have used the crates.io: Rust Package Registry instead of GitHub - FlashSystems/tokio-fastcgi: Async FastCGI handler library for Tokio.rs and this works quite fine.
Will update the post as soon as the program is available on GH.

This is now the simple tool for checking fast cgi (fcgi) servers GitHub - git001/fastcgi-healhcheck: A small tool to check if a fast cgi server is reachable

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.