Native Rust library for FastCGI

Related tags

GUI rust-gfcgi
Overview

The FastCGI Rust implementation.

Build Status docs.rs Cargo MIT licensed

Description

gfcgi is a native Rust library for FastCGI.
This library supports multithreaded socket listeners and HTTP-instances multiplexed onto a single connection.

About FastCGI

FastCGI is a great solution to handling HTTP-requests without overhead. Completely supporting HTTP or HTTPS by any of the leading popular web-servers (Apache HTTPd, nginx, etc).

Specification

Example

Import the library within your code.

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

An example of a 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 threads if the spawn feature is set 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]
You might also like...
OS native dialogs for Windows, MacOS, and Linux

💾 nfd2 nfd2 is a Rust binding to the nativefiledialog library, that provides a convenient cross-platform interface to opening file dialogs on Windows

Native Maps for Web, Mobile and Desktop
Native Maps for Web, Mobile and Desktop

mapr Native Maps for Web, Mobile and Linux A map rendering library written in Rust. Example | Book | API | Chat in Matrix Space Project State This pro

Generate Anchor IDL for Native Solana Programs.

Native Solana To Anchor IDL Autogenerate Anchor IDL from programs written in Native Solana. Disclaimer The instructions must follow strict set of rule

Provides core language-agnostic functionality for LiveView Native across platforms

LiveView Native Core This repository contains an implementation of the LiveView Native core library, which is intended to handle all the details which

An easy-to-use, 2D GUI library written entirely in Rust.

Conrod An easy-to-use, 2D GUI library written entirely in Rust. Guide What is Conrod? A Brief Summary Screenshots and Videos Feature Overview Availabl

Rust bindings for the FLTK GUI library.
Rust bindings for the FLTK GUI library.

fltk-rs Rust bindings for the FLTK Graphical User Interface library. The FLTK crate is a crossplatform lightweight gui library which can be statically

Idiomatic, GTK+-based, GUI library, inspired by Elm, written in Rust
Idiomatic, GTK+-based, GUI library, inspired by Elm, written in Rust

Relm Asynchronous, GTK+-based, GUI library, inspired by Elm, written in Rust. This library is in beta stage: it has not been thoroughly tested and its

Clear Coat is a Rust wrapper for the IUP GUI library.

Clear Coat Clear Coat is a Rust wrapper for the IUP GUI library. IUP uses native controls and has Windows and GTK backends. A macOS backend has been o

A cross-platform GUI library for Rust, inspired by Elm
A cross-platform GUI library for Rust, inspired by Elm

Iced A cross-platform GUI library for Rust focused on simplicity and type-safety. Inspired by Elm. Features Simple, easy-to-use, batteries-included AP

Comments
  • Wrong FastCGI request header

    Wrong FastCGI request header

    Hi,

    I have some issue with basic example - thread 'main' panicked at 'Wron FastCGI request header'

    Env: Windows 10 Nginx 1.10 Rust 1.14

    Nginx conf: server { ... location / { fastcgi_pass 127.0.0.1:4128; include fastcgi_params; } ... }

    Additional debug info:

    //let h = http::Request::fcgi_header(self.stream); // println!("{:?}", h); Header { version: 1, type_: 1, request_id: 1, content_length: 8, padding_length: 0, reserved: [0] } Header { version: 1, type_: 4, request_id: 1, content_length: 827, padding_length: 5, reserved: [0] } Header { version: 0, type_: 0, request_id: 0, content_length: 1, padding_length: 4, reserved: [0] }

    opened by hitok 2
Owner
Andrey Gridchin
Senior specialized on web-development and software architect
Andrey Gridchin
Simple and portable (but not inflexible) GUI library in C that uses the native GUI technologies of each platform it supports.

libui: a portable GUI library for C This README is being written. Status It has come to my attention that I have not been particularly clear about how

Pietro Gagliardi 10.4k Dec 31, 2022
A tiny, neat C library that portably invokes native file open and save dialogs.

Native File Dialog A tiny, neat C library that portably invokes native file open, folder select and save dialogs. Write dialog code once and have it p

Michael Labbe 1.5k Dec 28, 2022
A data-first Rust-native UI design toolkit.

Druid A data-first Rust-native UI toolkit. Druid is an experimental Rust-native UI toolkit. Its main goal is to offer a polished user experience. Ther

null 8.2k Dec 31, 2022
Rust bindings to the minimalist, native, cross-platform UI toolkit `libui`

Improved User Interface A cross-platform UI toolkit for Rust based on libui iui: ui-sys: iui is a simple (about 4 kLOC of Rust), small (about 800kb, i

Rust Native UI Group 865 Dec 27, 2022
Truly cross platform, truly native. multiple backend GUI for rust

WIP: Sauron-native a rust UI library that conquers all platforms ranging from desktop to mobile devices. An attempt to create a truly native, truly cr

Jovansonlee Cesar 627 Jan 5, 2023
Winsafe-examples - Examples of native Windows applications written in Rust with WinSafe.

WinSafe examples This repo contains several examples of native Win32 applications written in Rust with WinSafe. All examples follow the same program s

Rodrigo 40 Dec 14, 2022
Example for Rust Android Native Development

Android console application example project based on rust & cargo-xdk

Zhuo Zhang 4 Mar 17, 2022
Windows Native Undocumented API for Rust Language 🔥

Windows Native   The Windows-Native Rust library provides a convenient and safe way to access the native Windows undocumented APIs using the Rust prog

null 3 Aug 22, 2023
Crate for simple implementation of Component for Native API 1C:Enterprise written in rust

Гайд по использованию на русском языке можно посмотреть здесь и задать вопросы по использованию, но не оставляйте там комментарии об ошибках, т.к. там

Maxim Kozlov 40 Sep 30, 2023
OS-native file dialogs on Linux, OS X and Windows

nfd-rs nfd-rs is a Rust binding to the library nativefiledialog, that provides a convenient cross-platform interface to opening file dialogs on Linux,

Saurav Sachidanand 152 Nov 9, 2022