Fastcgi client implemented for Rust.
Notice: This crate is not productive yet, please do not use in production.
```rust use fastcgi_client::{Client, Params}; use std::{env, io}; use std::net::TcpStream;
let scriptfilename = env::currentdir() .unwrap() .join("tests") .join("php") .join("index.php"); let scriptfilename = scriptfilename.tostr().unwrap(); let scriptname = "/index.php";
// Connect to php-fpm default listening address. let stream = TcpStream::connect(("127.0.0.1", 9000)).unwrap(); let mut client = Client::new(stream, false);
// Fastcgi params, please reference to nginx-php-fpm config. let params = Params::withpredefine() .setrequestmethod("GET") .setscriptname(scriptname) .setscriptfilename(scriptfilename) .setrequesturi(scriptname) .setdocumenturi(scriptname) .setremoteaddr("127.0.0.1") .setremoteport("12345") .setserveraddr("127.0.0.1") .setserverport("80") .setservername("jmjoy-pc") .setcontenttype("") .setcontent_length("0");
// Fetch fastcgi server(php-fpm) response. let output = client.do_request(¶ms, &mut io::empty()).unwrap();
// "Content-type: text/html; charset=UTF-8\r\n\r\nhello" let stdout = String::fromutf8(output.getstdout().unwrap()).unwrap();
assert!(stdout.contains("Content-type: text/html; charset=UTF-8")); assert!(stdout.contains("hello")); asserteq!(output.getstderr(), None); ```