Skip to main content

Client

Struct Client 

Source
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

Source

pub fn builder() -> ClientBuilder

Source

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.

Source

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 Preview and 100 Continue negotiation when applicable,
  • and returns the parsed ICAP ParsedResponse.
Source

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.

Source

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.

Source

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());
Source

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()).

Source

pub async fn send_streaming_reader<R>( &self, req: &Request, reader: R, ) -> IcapResult<ParsedResponse>
where R: AsyncRead + Unpin + Send,

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more