[−][src]Struct fastly::handle::ResponseHandle
A low-level interface to HTTP responses.
Along with a BodyHandle
, a response handle can be immediately sent downstream to the client
using send_to_client()
, or streamed back to the client with
stream_to_client
.
Implementations
impl ResponseHandle
[src]
pub const INVALID: Self
[src]
An invalid handle.
pub fn is_valid(&self) -> bool
[src]
Return true if the response handle is valid.
pub fn is_invalid(&self) -> bool
[src]
Return true if the response handle is invalid.
pub fn new() -> Self
[src]
Acquire a new response handle.
pub fn get_header_names<'a>(
&'a self,
max_len: usize
) -> impl Iterator<Item = Result<HeaderName, BufferSizeError>> + 'a
[src]
&'a self,
max_len: usize
) -> impl Iterator<Item = Result<HeaderName, BufferSizeError>> + 'a
Read a response's header names via a buffer of the provided size.
If there is a header name that is longer than the provided buffer, this will return a
BufferSizeError
; you can retry with a larger buffer size if necessary.
pub fn get_header_values<'a>(
&'a self,
name: &'a HeaderName,
max_len: usize
) -> impl Iterator<Item = Result<HeaderValue, BufferSizeError>> + 'a
[src]
&'a self,
name: &'a HeaderName,
max_len: usize
) -> impl Iterator<Item = Result<HeaderValue, BufferSizeError>> + 'a
Get a response's header values given a header name, via a buffer of the provided size.
If there is a header value that is longer than the provided buffer, this will return a
BufferSizeError
; you can retry with a larger buffer size if necessary.
Examples
Collect all the header values into a Vec
:
let name = HeaderName::from_static("My-App-Header"); let buf_size = 128; let header_values: Vec<HeaderValue> = response .get_header_values(&name, buf_size) .collect::<Result<Vec<HeaderValue>, _>>()?;
To try again with a larger buffer if the first call fails, you can use
unwrap_or_else
:
let name = HeaderName::from_static("My-App-Header"); let buf_size = 128; // Collect header values into a `Vec<HeaderValue>`, with a buffer size of `128`. // If the first call fails, print our error and then try to collect header values // again. The second call will use a larger buffer size of `1024`. let header_values: Vec<HeaderValue> = response .get_header_values(&name, buf_size) .collect::<Result<_, _>>() .unwrap_or_else(|err: BufferSizeError| { eprintln!("buffer size error: {}", err); let larger_buf_size = 1024; response .get_header_values(&name, larger_buf_size) .collect::<Result<_, _>>() .unwrap() });
pub fn set_header_values<'a, I>(&mut self, name: &HeaderName, values: I) where
I: IntoIterator<Item = &'a HeaderValue>,
[src]
I: IntoIterator<Item = &'a HeaderValue>,
Set a response's header values given a header name and a collection of header values.
pub fn get_header_value(
&self,
name: &HeaderName,
max_len: usize
) -> Result<Option<HeaderValue>, BufferSizeError>
[src]
&self,
name: &HeaderName,
max_len: usize
) -> Result<Option<HeaderValue>, BufferSizeError>
Get a response's HeaderValue
, given the HeaderName
.
If there are multiple values associated with the name, then the first one is returned.
If the value is longer than the provided buffer, this will return a
BufferSizeError
; you can retry with a larger buffer size if necessary.
If no header exists with the given name, this function will return Ok(None)
.
pub fn insert_header(&mut self, name: &HeaderName, value: &HeaderValue)
[src]
Insert a new key-value pair into the response's headers.
If this HeaderName
key already existed in the response's headers, associated
HeaderValue
s will be overwritten. To preserve pre-existing values, use
append_header
instead.
pub fn append_header(&mut self, name: &HeaderName, value: &HeaderValue)
[src]
Append a new key-value pair to the response's headers.
If this HeaderName
key already existed in the response's headers, the new
HeaderValue
s will be added the end of the values associated with that key. To
overwrite other pre-existing values, use insert_header
instead.
pub fn remove_header(&mut self, name: &HeaderName) -> bool
[src]
Remove a header from the response, returning true
if it was formerly present or false
otherwise.
pub fn set_status(&mut self, status: StatusCode)
[src]
Set the response's
StatusCode
.
pub fn get_status(&self) -> StatusCode
[src]
Get the response's
StatusCode
.
pub fn get_version(&self) -> Version
[src]
Get the response's
Version
.
pub fn set_version(&mut self, v: Version)
[src]
Set the response's
Version
.
pub fn send_to_client(self, body: BodyHandle)
[src]
Immediately begin sending this response downstream to the client with the given body.
pub fn send_downstream(self, body: BodyHandle)
[src]
renamed to `ResponseHandle::send_to_client()
pub fn stream_to_client(self, body: BodyHandle) -> StreamingBodyHandleⓘNotable traits for StreamingBodyHandle
impl Write for StreamingBodyHandle
[src]
Notable traits for StreamingBodyHandle
impl Write for StreamingBodyHandle
Immediately begin sending this response downstream to the client, and return a
StreamingBodyHandle
that can accept further data to send.
pub fn send_downstream_streaming(self, body: BodyHandle) -> StreamingBodyHandleⓘNotable traits for StreamingBodyHandle
impl Write for StreamingBodyHandle
[src]
Notable traits for StreamingBodyHandle
impl Write for StreamingBodyHandle
renamed to `ResponseHandle::stream_to_client()
Trait Implementations
impl Debug for ResponseHandle
[src]
impl Eq for ResponseHandle
[src]
impl Hash for ResponseHandle
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl PartialEq<ResponseHandle> for ResponseHandle
[src]
fn eq(&self, other: &ResponseHandle) -> bool
[src]
fn ne(&self, other: &ResponseHandle) -> bool
[src]
impl StructuralEq for ResponseHandle
[src]
impl StructuralPartialEq for ResponseHandle
[src]
Auto Trait Implementations
impl RefUnwindSafe for ResponseHandle
impl Send for ResponseHandle
impl Sync for ResponseHandle
impl Unpin for ResponseHandle
impl UnwindSafe for ResponseHandle
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,