Skip to main content

ServiceOptions

Struct ServiceOptions 

Source
pub struct ServiceOptions { /* private fields */ }
Expand description

Configuration for generating an ICAP OPTIONS response.

Implementations§

Source§

impl ServiceOptions

Source

pub fn new() -> Self

Create a new OPTIONS config without an ISTag.

ICAP success responses require an explicit ISTag. Call with_static_istag or with_istag_provider before registering this config on a server route.

Source

pub fn with_istag_provider<F>(self, f: F) -> Self
where F: Fn(&IncomingRequest) -> String + Send + Sync + 'static,

Provide a dynamic ISTag provider that will be invoked for each request (including OPTIONS). The closure should be fast and lock-free if possible.

The provider returns the logical tag value. It may return a raw token such as policy-1 or a base64-like value such as QUJD+/8=; generated ICAP responses quote the value on the wire per RFC 3507.

Typical sources include: a version string stored in an Arc<RwLock<String>>, an atomic epoch counter, or a lightweight in-process cache.

§Example
let tag = Arc::new(RwLock::new(String::from("respmod-1.0")));
let opts = ServiceOptions::new()
    .with_istag_provider({
        let tag = tag.clone();
        move |_: &IncomingRequest| tag.read().unwrap().clone()
    });
Source

pub fn with_static_istag(self, istag: &str) -> Self

Use a static ISTag for responses.

The value may be passed as a raw token such as policy-1 or QUJD+/8=. Generated ICAP responses quote it on the wire per RFC 3507.

Source

pub fn with_dynamic_istag(self, handle: IsTagHandle) -> Self

Use an IsTagHandle as the ISTag source.

This is the preferred way to wire up a dynamically-rotating tag. The handle can be shared with route handlers via Clone; call IsTagHandle::set from anywhere to rotate the tag atomically.

Source

pub fn with_service(self, service: &str) -> Self

Set the human-readable service description.

Source

pub const fn with_max_object_size(self, bytes: usize) -> Self

Set the maximum embedded HTTP object size, in bytes.

The value is advertised in OPTIONS as Max-Object-Size and enforced by the server for this service by counting decoded ICAP chunked body bytes. Embedded HTTP Content-Length is not trusted for enforcement because peers may send a value that differs from the actual body.

Source

pub const fn with_options_ttl(self, ttl: u32) -> Self

Set Options-TTL (seconds).

Source

pub fn with_service_id(self, service_id: &str) -> Self

Set short service ID.

Source

pub fn add_allow(self, capability: &str) -> Self

Add a capability to Allow (e.g. "204").

Source

pub fn allow_204(self) -> Self

Advertise support for 204 No Content no-modification responses.

This is equivalent to add_allow("204"), but avoids stringly typed capability values in normal service configuration.

Source

pub fn allow_206(self) -> Self

Advertise support for 206 Partial Content no-modification responses.

This is equivalent to add_allow("206"), but avoids stringly typed capability values in normal service configuration.

Source

pub const fn with_preview(self, preview: u32) -> Self

Set Preview size (bytes).

Source

pub fn add_transfer_rule( self, extension: &str, behavior: TransferBehavior, ) -> Self

Add rule for a file extension (e.g. “pdf”, “exe”).

Source

pub const fn with_default_transfer_behavior( self, behavior: TransferBehavior, ) -> Self

Set default transfer behavior (applied when an extension is not matched).

Source

pub fn add_custom_header(self, name: &str, value: &str) -> Self

Add a custom header.

Source

pub fn with_opt_body(self, body_type: &str, body: Vec<u8>) -> Self

Advertise an opt-body in the service’s OPTIONS response (RFC 3507 §4.10).

The generated OPTIONS response sets Encapsulated: opt-body=0, adds an Opt-body-type: <body_type> header, and serializes body as a single ICAP chunk terminated by 0\r\n\r\n. body_type describes the payload (for example "text/plain" or a service-defined token); it is required whenever an opt-body is present and is checked by ServiceOptions::validate at server build time.

A client reading the OPTIONS response receives the dechunked bytes via Response::body().

§Examples
use icap_rs::server::options::ServiceOptions;

let options = ServiceOptions::new()
    .with_static_istag("opt-1.0")
    .with_service("Scanner")
    .with_opt_body("text/plain", b"server info".to_vec());
Source

pub fn validate(&self) -> Result<(), String>

Validate invariants for this configuration.

For dynamic ISTag providers it is not possible to validate non-emptiness at configuration time; perform validation when computing the value if needed.

Trait Implementations§

Source§

impl Clone for ServiceOptions

Source§

fn clone(&self) -> ServiceOptions

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 Default for ServiceOptions

Source§

fn default() -> Self

Returns the “default value” for a type. 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