pub struct Client { /* private fields */ }Expand description
High-level ICAP client with connection reuse and Preview negotiation.
Construct via Client::builder() and send requests using Client::send
/ Client::send_streaming / Client::send_streaming_reader.
You can also generate the exact wire bytes
without sending using Client::get_request / Client::get_request_wire.
Implementations§
Source§impl Client
impl Client
pub fn builder() -> ClientBuilder
Sourcepub fn get_request(&self, req: &Request) -> IcapResult<Vec<u8>>
pub fn get_request(&self, req: &Request) -> IcapResult<Vec<u8>>
Return the raw ICAP request as wire-format bytes (no I/O).
Useful for debugging or for printing what would be sent without actually opening a connection.
Sourcepub async fn send(&self, req: &Request) -> IcapResult<ParsedResponse>
pub async fn send(&self, req: &Request) -> IcapResult<ParsedResponse>
Send an prepared ICAP request with an embedded HTTP message.
This method:
- writes ICAP headers and the embedded HTTP headers/body,
- handles
Previewand100 Continuenegotiation when applicable, - and returns the parsed ICAP
ParsedResponse.
Sourcepub async fn invalidate_options_cache(&self)
pub async fn invalidate_options_cache(&self)
Drop all cached OPTIONS results, forcing a re-fetch on the next request.
No-op when the OPTIONS cache (see
ClientBuilder::with_options_cache)
is not enabled.
Sourcepub async fn send_streaming<P: AsRef<Path>>(
&self,
req: &Request,
file_path: P,
) -> IcapResult<ParsedResponse>
pub async fn send_streaming<P: AsRef<Path>>( &self, req: &Request, file_path: P, ) -> IcapResult<ParsedResponse>
Send a request and stream the body from a file using ICAP chunked encoding.
Sourcepub async fn send_raw(&self, raw: &[u8]) -> IcapResult<ParsedResponse>
pub async fn send_raw(&self, raw: &[u8]) -> IcapResult<ParsedResponse>
Send a pre-formatted ICAP session as raw bytes.
The bytes are written to the server verbatim — no ICAP headers are added,
no Encapsulated offset is computed, and no preview negotiation takes
place. The server’s response is read back and returned as a
ParsedResponse exactly like Client::send.
Use this when you want to hand-craft the wire bytes yourself, reproduce
a specific packet capture, or send an unusual request that the Request
builder does not support.
Connection-policy (keep-alive / close) and the global operation timeout
configured on the ClientBuilder still apply.
§Example
The HTTP request head and body are formatted manually, including the
chunked body framing (5\r\nHello\r\n0\r\n\r\n) required by ICAP.
The Encapsulated offsets must be correct: req-hdr=0 means the
HTTP request headers start at byte 0 of the encapsulated section, and
req-body=N is the byte offset where the chunked body begins (i.e.
the length of the HTTP request head block).
use icap_rs::Client;
let client = Client::builder().host("127.0.0.1").port(1344).build();
// Hand-crafted REQMOD: scan a small POST body.
// `req-body` equals the byte length of the HTTP request head (`http_head_len`).
let http_head = b"POST /upload HTTP/1.1\r\nHost: app\r\n\r\n"; // 36 bytes
let http_head_len = http_head.len(); // must match the req-body offset below
let raw = format!(
"REQMOD icap://127.0.0.1:1344/scan ICAP/1.0\r\n\
Host: 127.0.0.1\r\n\
Encapsulated: req-hdr=0, req-body={http_head_len}\r\n\r\n\
POST /upload HTTP/1.1\r\nHost: app\r\n\r\n\
5\r\nHello\r\n0\r\n\r\n"
);
let resp = client.send_raw_str(&raw).await?;
println!("status: {}", resp.status_code());Sourcepub async fn send_raw_str(&self, raw: &str) -> IcapResult<ParsedResponse>
pub async fn send_raw_str(&self, raw: &str) -> IcapResult<ParsedResponse>
Convenience wrapper around Client::send_raw that accepts a &str.
Equivalent to client.send_raw(raw.as_bytes()).
Sourcepub async fn send_streaming_reader<R>(
&self,
req: &Request,
reader: R,
) -> IcapResult<ParsedResponse>
pub async fn send_streaming_reader<R>( &self, req: &Request, reader: R, ) -> IcapResult<ParsedResponse>
Send a request and stream body bytes from any AsyncRead source using ICAP chunked encoding.
This API avoids requiring an in-memory Vec<u8> body in the request object.
Pair it with Request::with_http_request_head(...) / with_http_response_head(...)
for head-only embedded HTTP.
Sourcepub fn get_request_wire(
&self,
req: &Request,
streaming: bool,
) -> IcapResult<Vec<u8>>
pub fn get_request_wire( &self, req: &Request, streaming: bool, ) -> IcapResult<Vec<u8>>
Build the exact wire representation of a request, including preview tail when applicable.
Set streaming=true when the body will be supplied later through a
streaming API. This makes the generated wire advertise an encapsulated
body offset without embedding body bytes in the returned buffer.