pub struct Response<D = Outgoing> { /* private fields */ }Expand description
Representation of an ICAP response.
The type parameter is a direction marker:
Outgoingis the default builder shape used by servers.Parsedis 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>
impl<D> Response<D>
Sourcepub const fn status_code(&self) -> StatusCode
pub const fn status_code(&self) -> StatusCode
Return the response status code.
Sourcepub fn status_text(&self) -> &str
pub fn status_text(&self) -> &str
Return the response reason.
Sourcepub fn get_header(&self, name: &str) -> Option<&HeaderValue>
pub fn get_header(&self, name: &str) -> Option<&HeaderValue>
Get a header value by name.
Sourcepub const fn use_original_body_offset(&self) -> Option<usize>
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.
Sourcepub fn has_header(&self, name: &str) -> bool
pub fn has_header(&self, name: &str) -> bool
Check whether a header exists.
Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Whether the response indicates success (2XX).
Sourcepub fn is_client_error(&self) -> bool
pub fn is_client_error(&self) -> bool
Whether the response indicates a client error (4xx).
Sourcepub fn is_server_error(&self) -> bool
pub fn is_server_error(&self) -> bool
Whether the response indicates a server error (5xx).
Source§impl Response<Parsed>
impl Response<Parsed>
Sourcepub fn from_raw(raw: &[u8]) -> IcapResult<Self>
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.
Sourcepub const fn chunk_trailers(&self) -> &HeaderMap
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>
impl Response<Outgoing>
Sourcepub fn new(status_code: StatusCode, status_text: &str) -> Self
pub fn new(status_code: StatusCode, status_text: &str) -> Self
Create a new ICAP response with the given status code and status text.
Sourcepub fn ok() -> Self
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.
Sourcepub fn ok_with_istag(istag: &str) -> IcapResult<Self>
pub fn ok_with_istag(istag: &str) -> IcapResult<Self>
Shortcut for a 200 OK response with a validated ISTag.
Sourcepub fn no_content() -> Self
pub fn no_content() -> Self
Shortcut for a 204 No Content response.
Sourcepub fn no_content_with_istag(istag: &str) -> IcapResult<Self>
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.
Sourcepub fn partial_content() -> Self
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.
Sourcepub fn partial_content_with_istag(istag: &str) -> IcapResult<Self>
pub fn partial_content_with_istag(istag: &str) -> IcapResult<Self>
Shortcut for a 206 Partial Content response with a validated ISTag.
Sourcepub fn no_content_with_headers(headers: HeaderMap) -> IcapResult<Self>
pub fn no_content_with_headers(headers: HeaderMap) -> IcapResult<Self>
Shortcut for a 204 No Content response with headers.
Sourcepub fn try_add_header(self, name: &str, value: &str) -> IcapResult<Self>
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.
Sourcepub fn add_header(self, name: &str, value: &str) -> Self
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.
Sourcepub fn try_set_istag(self, istag: &str) -> IcapResult<Self>
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.
Sourcepub fn with_body_string(self, body: &str) -> Self
pub fn with_body_string(self, body: &str) -> Self
Set the response body from a string.
Sourcepub fn to_raw(&self) -> IcapResult<Vec<u8>>
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.
Sourcepub fn remove_header(&mut self, name: &str) -> Option<HeaderValue>
pub fn remove_header(&mut self, name: &str) -> Option<HeaderValue>
Remove a header by name.
Sourcepub fn with_http_request(self, http: &Request<Vec<u8>>) -> IcapResult<Self>
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=..].
Sourcepub fn with_http_response(self, http: &Response<Vec<u8>>) -> IcapResult<Self>
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=..].
Sourcepub fn with_http_request_head_and_original_body(
self,
head: &Request<()>,
offset: usize,
) -> IcapResult<Self>
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>.
Sourcepub fn with_http_response_head_and_original_body(
self,
head: &Response<()>,
offset: usize,
) -> IcapResult<Self>
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>.