pub struct ServiceOptions { /* private fields */ }Expand description
Configuration for generating an ICAP OPTIONS response.
Implementations§
Source§impl ServiceOptions
impl ServiceOptions
Sourcepub fn new() -> Self
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.
Sourcepub fn with_istag_provider<F>(self, f: F) -> Self
pub fn with_istag_provider<F>(self, f: F) -> Self
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()
});Sourcepub fn with_static_istag(self, istag: &str) -> Self
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.
Sourcepub fn with_dynamic_istag(self, handle: IsTagHandle) -> Self
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.
Sourcepub fn with_service(self, service: &str) -> Self
pub fn with_service(self, service: &str) -> Self
Set the human-readable service description.
Sourcepub const fn with_max_object_size(self, bytes: usize) -> Self
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.
Sourcepub const fn with_options_ttl(self, ttl: u32) -> Self
pub const fn with_options_ttl(self, ttl: u32) -> Self
Set Options-TTL (seconds).
Sourcepub fn with_service_id(self, service_id: &str) -> Self
pub fn with_service_id(self, service_id: &str) -> Self
Set short service ID.
Sourcepub fn allow_204(self) -> Self
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.
Sourcepub fn allow_206(self) -> Self
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.
Sourcepub const fn with_preview(self, preview: u32) -> Self
pub const fn with_preview(self, preview: u32) -> Self
Set Preview size (bytes).
Sourcepub fn add_transfer_rule(
self,
extension: &str,
behavior: TransferBehavior,
) -> Self
pub fn add_transfer_rule( self, extension: &str, behavior: TransferBehavior, ) -> Self
Add rule for a file extension (e.g. “pdf”, “exe”).
Sourcepub const fn with_default_transfer_behavior(
self,
behavior: TransferBehavior,
) -> Self
pub const fn with_default_transfer_behavior( self, behavior: TransferBehavior, ) -> Self
Set default transfer behavior (applied when an extension is not matched).
Sourcepub fn add_custom_header(self, name: &str, value: &str) -> Self
pub fn add_custom_header(self, name: &str, value: &str) -> Self
Add a custom header.
Sourcepub fn with_opt_body(self, body_type: &str, body: Vec<u8>) -> Self
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());Trait Implementations§
Source§impl Clone for ServiceOptions
impl Clone for ServiceOptions
Source§fn clone(&self) -> ServiceOptions
fn clone(&self) -> ServiceOptions
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more