[−][src]Crate fastcgi_client
Fastcgi client implemented for Rust.
Example
use fastcgi_client::{Address, ClientBuilder, Params}; use std::{env, io}; let script_filename = env::current_dir() .unwrap() .join("tests") .join("php") .join("index.php"); let script_filename = script_filename.to_str().unwrap(); let script_name = "/index.php"; // Connect to php-fpm default listening address. let mut client = ClientBuilder::new(Address::Tcp("127.0.0.1", 9000)).build().unwrap(); // Fastcgi params, please reference to nginx-php-fpm config. let params = Params::with_predefine() .set_request_method("GET") .set_script_name(script_name) .set_script_filename(script_filename) .set_request_uri(script_name) .set_document_uri(script_name) .set_remote_addr("127.0.0.1") .set_remote_port("12345") .set_server_addr("127.0.0.1") .set_server_port("80") .set_server_name("jmjoy-pc") .set_content_type("") .set_content_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::from_utf8(output.get_stdout().unwrap()).unwrap(); dbg!(&stdout); assert!(stdout.contains("Content-type: text/html; charset=UTF-8")); assert!(stdout.contains("hello")); assert_eq!(output.get_stderr(), None);
Structs
Client | Client for handling communication between fastcgi server. |
ClientBuilder | Builder for fastcgi client, with connect/read/write timeout setting, and keep-alive setting, etc. |
Output | Output of fastcgi request, contains STDOUT and STDERR. |
Params | Fastcgi params, please reference to nginx-php-fpm fastcgi_params. |
Enums
Address | Fastcgi server address. |
ClientError | Client error, contain |
Type Definitions
ClientResult | Result of ClientError. |