Skip to main content

Response

Struct Response 

Source
pub struct Response<D = Outgoing> { /* private fields */ }
Expand description

Representation of an ICAP response.

The type parameter is a direction marker:

  • Outgoing is the default builder shape used by servers.
  • Parsed is returned by response parsing and client receive APIs.

Parsed responses expose read-only metadata and body accessors. Builder methods such as add_header, with_http_response, and to_raw are only available on outgoing responses.

Implementations§

Source§

impl<D> Response<D>

Source

pub fn version(&self) -> &str

Return the ICAP protocol version string.

Source

pub const fn status_code(&self) -> StatusCode

Return the response status code.

Source

pub fn status_text(&self) -> &str

Return the response reason.

Source

pub fn body(&self) -> &[u8]

Return the response body bytes.

Source

pub fn get_header(&self, name: &str) -> Option<&HeaderValue>

Get a header value by name.

Source

pub const fn headers(&self) -> &HeaderMap

Return a read-only view of all ICAP headers.

Source

pub const fn use_original_body_offset(&self) -> Option<usize>

Return the use-original-body offset from a parsed or constructed 206 response.

When present, the response carries an ICAP zero-chunk extension telling the client to append the original HTTP entity body starting at this byte offset after any partial body bytes included in the 206 response.

Source

pub fn has_header(&self, name: &str) -> bool

Check whether a header exists.

Source

pub fn is_success(&self) -> bool

Whether the response indicates success (2XX).

Source

pub fn is_client_error(&self) -> bool

Whether the response indicates a client error (4xx).

Source

pub fn is_server_error(&self) -> bool

Whether the response indicates a server error (5xx).

Source§

impl Response<Parsed>

Source

pub fn from_raw(raw: &[u8]) -> IcapResult<Self>

Parse an ICAP response from raw bytes.

When the response contains an embedded HTTP message, Response::body returns the embedded HTTP head followed by the dechunked HTTP entity body. ICAP chunk-size metadata is not preserved.

Source

pub const fn chunk_trailers(&self) -> &HeaderMap

Return chunk trailer headers that accompanied the response body.

RFC 7230 §4.1.2 (applied by RFC 3507 §6.3) allows an ICAP server to append HTTP-style Name: Value trailer headers after the zero chunk. This method returns those headers as parsed from the wire.

The map is empty when no trailers were present.

Source§

impl Response<Outgoing>

Source

pub fn new(status_code: StatusCode, status_text: &str) -> Self

Create a new ICAP response with the given status code and status text.

Source

pub fn ok() -> Self

Shortcut for a 200 OK response.

Successful ICAP responses require a valid ISTag before serialization. Use Response::ok_with_istag when the tag is known at construction time.

Source

pub fn ok_with_istag(istag: &str) -> IcapResult<Self>

Shortcut for a 200 OK response with a validated ISTag.

Source

pub fn no_content() -> Self

Shortcut for a 204 No Content response.

Source

pub fn no_content_with_istag(istag: &str) -> IcapResult<Self>

Shortcut for a 204 No Content response with a validated ISTag.

This is the common “no modification needed” response for clients that advertised Allow: 204 or used Preview.

Source

pub fn partial_content() -> Self

Shortcut for a 206 Partial Content response.

Pair this with Response::with_http_request_head_and_original_body or Response::with_http_response_head_and_original_body to emit the RFC 3507 use-original-body marker.

Source

pub fn partial_content_with_istag(istag: &str) -> IcapResult<Self>

Shortcut for a 206 Partial Content response with a validated ISTag.

Source

pub fn no_content_with_headers(headers: HeaderMap) -> IcapResult<Self>

Shortcut for a 204 No Content response with headers.

Source

pub fn try_add_header(self, name: &str, value: &str) -> IcapResult<Self>

Try to add or overwrite a header.

Setting ISTag here is discouraged; prefer Response::try_set_istag.

Source

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

Add or overwrite a header. NOTE: Setting ISTag here is discouraged; prefer try_set_istag().

§Panics

Panics if name or value is not a valid HTTP header field. Invalid ISTag values are ignored for compatibility with previous releases; use Response::try_add_header or Response::try_set_istag for fallible handling.

Source

pub fn try_set_istag(self, istag: &str) -> IcapResult<Self>

Set ISTag header with validation.

RFC 3507 defines ISTag as a quoted-string. For compatibility, this method accepts an unquoted token such as QUJD+/8=, but stores it as a quoted wire value ("QUJD+/8="). Response parsing remains more lenient and accepts unquoted token/base64-like peer values for interoperability. Returns Self on success; otherwise Error::InvalidISTag.

Source

pub fn with_body(self, body: &[u8]) -> Self

Set the response body from bytes.

Source

pub fn with_body_string(self, body: &str) -> Self

Set the response body from a string.

Source

pub fn to_raw(&self) -> IcapResult<Vec<u8>>

Serialize into raw ICAP bytes.

This validates ICAP-specific response invariants before writing: successful responses require a valid ISTag, 204 must use Encapsulated: null-body=0, and embedded HTTP bodies are framed per RFC 3507 with unchunked HTTP heads and chunked encapsulated entity bodies.

Source

pub fn remove_header(&mut self, name: &str) -> Option<HeaderValue>

Remove a header by name.

Source

pub fn with_http_request(self, http: &Request<Vec<u8>>) -> IcapResult<Self>

Attach an embedded HTTP request (for REQMOD flows). Sets Encapsulated: req-hdr=0[, req-body=..].

Source

pub fn with_http_response(self, http: &Response<Vec<u8>>) -> IcapResult<Self>

Attach an embedded HTTP response (for RESPMOD flows). Sets Encapsulated: res-hdr=0[, res-body=..].

Source

pub fn with_http_request_head_and_original_body( self, head: &Request<()>, offset: usize, ) -> IcapResult<Self>

Attach an embedded HTTP request head and emit a 206 use-original-body marker.

The serialized response will contain the HTTP request head, no adapted body bytes, and a final ICAP chunk 0; use-original-body=<offset>.

Source

pub fn with_http_response_head_and_original_body( self, head: &Response<()>, offset: usize, ) -> IcapResult<Self>

Attach an embedded HTTP response head and emit a 206 use-original-body marker.

The serialized response will contain the HTTP response head, no adapted body bytes, and a final ICAP chunk 0; use-original-body=<offset>.

Trait Implementations§

Source§

impl<D: Clone> Clone for Response<D>

Source§

fn clone(&self) -> Response<D>

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<D: Debug> Debug for Response<D>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<D> Display for Response<D>

Source§

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

Formats the ICAP response for debugging: status line, headers, and body (if present).

Auto Trait Implementations§

§

impl<D> Freeze for Response<D>

§

impl<D> RefUnwindSafe for Response<D>
where D: RefUnwindSafe,

§

impl<D> Send for Response<D>
where D: Send,

§

impl<D> Sync for Response<D>
where D: Sync,

§

impl<D> Unpin for Response<D>
where D: Unpin,

§

impl<D> UnsafeUnpin for Response<D>

§

impl<D> UnwindSafe for Response<D>
where D: UnwindSafe,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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