pub struct Client<S, M> { /* private fields */ }Expand description
Async client for handling communication between fastcgi server.
Implementations§
Source§impl<S> Client<TokioCompat<S>, ShortConn>
impl<S> Client<TokioCompat<S>, ShortConn>
Sourcepub fn new_tokio(stream: S) -> Self
Available on crate feature tokio only.
pub fn new_tokio(stream: S) -> Self
tokio only.Construct a Client Object with a Tokio stream under short connection
mode.
Requires the optional tokio feature, which exists purely as a
convenience adapter: Tokio defines its own I/O traits, so the stream is
wrapped with tokio_util::compat
before being handed to the runtime agnostic core. Without the feature,
bridge the stream yourself and call Client::new.
§Examples
use fastcgi_client::Client;
use tokio::net::TcpStream;
let tcp_stream = TcpStream::connect(("127.0.0.1", 9000)).await.unwrap();
let _tcp_client = Client::new_tokio(tcp_stream);
let unix_stream = UnixStream::connect("/run/php-fpm.sock").await.unwrap();
let _unix_client = Client::new_tokio(unix_stream);Source§impl<S: AsyncRead + AsyncWrite + Unpin> Client<S, ShortConn>
impl<S: AsyncRead + AsyncWrite + Unpin> Client<S, ShortConn>
Sourcepub fn new(stream: S) -> Self
pub fn new(stream: S) -> Self
Construct a Client object under short connection mode.
This constructor is runtime agnostic: it accepts any stream implementing
the futures_io AsyncRead + AsyncWrite traits, such as
smol::net::TcpStream, async_net::TcpStream, or a Tokio stream
wrapped by tokio_util::compat.
§Examples
use fastcgi_client::Client;
use smol::net::TcpStream;
let stream = TcpStream::connect(("127.0.0.1", 9000)).await.unwrap();
let _client = Client::new(stream);Sourcepub async fn execute_once<I: AsyncRead + Unpin>(
self,
request: Request<'_, I>,
) -> ClientResult<Response>
pub async fn execute_once<I: AsyncRead + Unpin>( self, request: Request<'_, I>, ) -> ClientResult<Response>
Send request and receive response from fastcgi server, under short connection mode.
Sourcepub async fn execute_once_stream<I: AsyncRead + Unpin>(
self,
request: Request<'_, I>,
) -> ClientResult<ResponseStream<S>>
pub async fn execute_once_stream<I: AsyncRead + Unpin>( self, request: Request<'_, I>, ) -> ClientResult<ResponseStream<S>>
Send request and receive response stream from fastcgi server, under short connection mode.
§Examples
use fastcgi_client::{io, response::Content, Client, Params, Request, StreamExt};
use tokio::net::TcpStream;
let stream = TcpStream::connect(("127.0.0.1", 9000)).await.unwrap();
let client = Client::new_tokio(stream);
let mut stream = client
.execute_once_stream(Request::new(Params::default(), io::empty()))
.await
.unwrap();
while let Some(content) = stream.next().await {
let content = content.unwrap();
match content {
Content::Stdout(out) => todo!(),
Content::Stderr(out) => todo!(),
}
}
}Source§impl<S> Client<TokioCompat<S>, KeepAlive>
impl<S> Client<TokioCompat<S>, KeepAlive>
Sourcepub fn new_keep_alive_tokio(stream: S) -> Self
Available on crate feature tokio only.
pub fn new_keep_alive_tokio(stream: S) -> Self
tokio only.Construct a Client Object with a Tokio stream under keep-alive mode.
Requires the optional tokio feature, which exists purely as a
convenience adapter: Tokio defines its own I/O traits, so the stream is
wrapped with tokio_util::compat
before being handed to the runtime agnostic core. Without the feature,
bridge the stream yourself and call Client::new_keep_alive.
§Examples
use fastcgi_client::Client;
use tokio::net::TcpStream;
let tcp_stream = TcpStream::connect(("127.0.0.1", 9000)).await.unwrap();
let _tcp_client = Client::new_keep_alive_tokio(tcp_stream);
let unix_stream = UnixStream::connect("/run/php-fpm.sock").await.unwrap();
let _unix_client = Client::new_keep_alive_tokio(unix_stream);Source§impl<S: AsyncRead + AsyncWrite + Unpin> Client<S, KeepAlive>
impl<S: AsyncRead + AsyncWrite + Unpin> Client<S, KeepAlive>
Sourcepub fn new_keep_alive(stream: S) -> Self
pub fn new_keep_alive(stream: S) -> Self
Construct a Client object under keep-alive mode.
This constructor is runtime agnostic: it accepts any stream implementing
the futures_io AsyncRead + AsyncWrite traits, such as
smol::net::TcpStream, async_net::TcpStream, or a Tokio stream
wrapped by tokio_util::compat.
§Examples
use fastcgi_client::Client;
use smol::net::TcpStream;
let stream = TcpStream::connect(("127.0.0.1", 9000)).await.unwrap();
let _client = Client::new_keep_alive(stream);Sourcepub async fn execute<I: AsyncRead + Unpin>(
&mut self,
request: Request<'_, I>,
) -> ClientResult<Response>
pub async fn execute<I: AsyncRead + Unpin>( &mut self, request: Request<'_, I>, ) -> ClientResult<Response>
Send request and receive response from fastcgi server, under keep alive connection mode.
Sourcepub async fn execute_stream<I: AsyncRead + Unpin>(
&mut self,
request: Request<'_, I>,
) -> ClientResult<ResponseStream<&mut S>>
pub async fn execute_stream<I: AsyncRead + Unpin>( &mut self, request: Request<'_, I>, ) -> ClientResult<ResponseStream<&mut S>>
Send request and receive response stream from fastcgi server, under keep alive connection mode.
§Examples
use fastcgi_client::{io, response::Content, Client, Params, Request, StreamExt};
use tokio::net::TcpStream;
let stream = TcpStream::connect(("127.0.0.1", 9000)).await.unwrap();
let mut client = Client::new_keep_alive_tokio(stream);
for _ in (0..3) {
let mut stream = client
.execute_stream(Request::new(Params::default(), io::empty()))
.await
.unwrap();
while let Some(content) = stream.next().await {
let content = content.unwrap();
match content {
Content::Stdout(out) => todo!(),
Content::Stderr(out) => todo!(),
}
}
}
}