[][src]Crate cgi

Easily create CGI (RFC 3875) programmes in Rust based on http

Installation & Usage

Cargo.toml:

[dependencies]
cgi = "0.1"

In the main function, call only cgi::handle(...), with a function that takes a cgi::Request and returns cgi::Response.

extern crate cgi;
 
fn main() { cgi::handle(|request: cgi::Request| -> cgi::Response {
     ...
})}

Hello World:

extern crate cgi;
 
fn main() { cgi::handle(|request: cgi::Request| -> cgi::Response {
    cgi::html_response(200, "<html><body><h1>Hello World!</h1></body></html>")
})}

It will parse & extract the CGI environmental variables, and HTTP request body to create Request, and convert your Response into the correct format and print to stdout. If this programme is not called as CGI (e.g. missing required environmental variables), it will panic.

Re-exports

pub extern crate http;

Functions

binary_response

Sends blob with that status code.

empty_response

A HTTP Reponse with no body and that HTTP status code, e.g. return cgi::empty_response(404); to return a HTTP 404 Not Found.

handle

Call F as a CGI programme.

html_response

Converts text to bytes (UTF8) and sends that as the body with that status_code and HTML Content-Type header.

string_response

Returns a simple plain text response.

Type Definitions

Request

A Vec<u8> Request from http

Response

A Vec<u8> Response from http