pub struct Server { /* private fields */ }Expand description
ICAP server.
Use Server::builder to construct and run an instance.
§Example
use icap_rs::{IcapResult, IncomingRequest, Method, Response, Server, ServiceOptions};
const ISTAG: &str = "scan-1.0";
#[tokio::main]
async fn main() -> IcapResult<()> {
let server = Server::builder()
.bind("127.0.0.1:1344")
.route(
"scan",
[Method::ReqMod],
|_req: IncomingRequest| async move {
Ok(Response::no_content_with_istag(ISTAG)?)
},
Some(ServiceOptions::new().with_static_istag(ISTAG).with_preview(1024)),
)
.build()
.await?;
server.run().await
}Implementations§
Source§impl Server
impl Server
Sourcepub fn builder() -> ServerBuilder
pub fn builder() -> ServerBuilder
Create a new ServerBuilder.
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Local socket address the server is bound to.
Useful after binding to an ephemeral port (127.0.0.1:0).
Sourcepub async fn run(self) -> IcapResult<()>
pub async fn run(self) -> IcapResult<()>
Sourcepub async fn run_until<F>(self, shutdown: F) -> IcapResult<()>
pub async fn run_until<F>(self, shutdown: F) -> IcapResult<()>
Run the accept loop until shutdown resolves, then drain active connections.
When shutdown completes the server stops accepting new connections and
signals all active keep-alive connections to close after their current
in-flight request completes. Idle connections (waiting for the next
request) are closed immediately. The method returns only after every
active connection handler has finished.
§Example
use icap_rs::{IcapResult, Server};
#[tokio::main]
async fn main() -> IcapResult<()> {
let server = Server::builder()
.bind("127.0.0.1:1344")
.build()
.await?;
// Shut down cleanly on Ctrl-C.
server.run_until(async { tokio::signal::ctrl_c().await.ok(); }).await
}Auto Trait Implementations§
impl !Freeze for Server
impl !RefUnwindSafe for Server
impl !UnwindSafe for Server
impl Send for Server
impl Sync for Server
impl Unpin for Server
impl UnsafeUnpin for Server
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more