Native Rust library for FastCGI
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
data
doc
example
src
.gitignore
.travis.yml
Cargo.toml
LICENSE
README.md
rust-gfcgi.iml
rustfmt.toml

README.md

The FastCGI Rust implementation.

Build Status docs.rs Cargo MIT licensed

Description

gfcgi a native Rust library for FastCGI.
Library is supporting multithreaded socket listener and HTTP-instances multiplexed onto a single connection.

About FastCGI

FastCGI it's great solutions to handling HTTP-requests without overhead. Completely supporting HTTP or HTTPS by any popular web-servers.

Specification

Example

Import the library within your code.

    extern crate gfcgi;
    
    use std::io::{Read, Write}; 
    use std::thread;

Some your router struct

    #[derive(Clone)]
    struct Router;
        
    impl Router
    {
        fn new() -> Self
        { 
            Router{}
        }
    }

Implement gfcgi::Handler trait for your router, all code in process method is optional

    impl gfcgi::Handler for Router
    {
        fn process(&self, request: &mut gfcgi::Request, response: &mut gfcgi::Response)
        {
            // get a header
            println!("{:?}", request.header_utf8(b"HTTP_HOST"));
    
            // read content
            let mut buf = Vec::new();
            request.read_to_end(&mut buf).unwrap();
            println!("{:?}", String::from_utf8(buf));
    
            // set header
            response.status(200);
            response.header_utf8("Content-type", "text/plain");
    
            // send content
            response.write(b"hello world!").expect("send body");
    
        }
    }

Now run listener, you can spawn thread if set spawn feature in Cargo.toml

    fn main()
    {
        let client = gfcgi::Client::new("127.0.0.1:4128");
    
        // run listener
        client.run(Router::new());
    
        if cfg!(feature = "spawn") {
            client.run(Router::new()); // spawn worker
        }
        
        thread::park(); // keep main process
    }

Planned

  • Role
    • responder
    • filter
    • authorizer
  • Header
    • get_values
    • get_values_result
    • unknown_type
    • begin_request
    • abort_request
    • end_request
    • params
    • stdin
    • data
    • stdout
    • stderr

Trace

socket
    stream
        connection
        handler
            request
            | → read headers
            | → [read body]
            response
            | ← write headers
            | ← [write body]