pub struct ResponseHeader { /* private fields */ }
Expand description
The HTTP response header type.
This type is similar to http::response::Parts but preserves header name case. ResponseHeader implements Deref for http::response::Parts so it can be used as it in most places.
Implementations§
Source§impl ResponseHeader
impl ResponseHeader
Sourcepub fn build(
code: impl TryInto<StatusCode>,
size_hint: Option<usize>,
) -> Result<Self>
pub fn build( code: impl TryInto<StatusCode>, size_hint: Option<usize>, ) -> Result<Self>
Create a new ResponseHeader with the given status code.
Sourcepub fn build_no_case(
code: impl TryInto<StatusCode>,
size_hint: Option<usize>,
) -> Result<Self>
pub fn build_no_case( code: impl TryInto<StatusCode>, size_hint: Option<usize>, ) -> Result<Self>
Create a new ResponseHeader with the given status code without preserving header case.
A ResponseHeader created from this type is more space efficient than those from Self::build().
Use this method if reading from or writing to HTTP/2 sessions where header case doesn’t matter anyway.
Sourcepub fn append_header(
&mut self,
name: impl IntoCaseHeaderName,
value: impl TryInto<HeaderValue>,
) -> Result<bool>
pub fn append_header( &mut self, name: impl IntoCaseHeaderName, value: impl TryInto<HeaderValue>, ) -> Result<bool>
Append the header name and value to self
.
If there are already some headers under the same name, a new value will be added without any others being removed.
Sourcepub fn insert_header(
&mut self,
name: impl IntoCaseHeaderName,
value: impl TryInto<HeaderValue>,
) -> Result<()>
pub fn insert_header( &mut self, name: impl IntoCaseHeaderName, value: impl TryInto<HeaderValue>, ) -> Result<()>
Insert the header name and value to self
.
Different from Self::append_header(), this method will replace all other existing headers under the same name (case insensitive).
Sourcepub fn remove_header<'a, N: ?Sized>(
&mut self,
name: &'a N,
) -> Option<HeaderValue>where
&'a N: 'a + AsHeaderName,
pub fn remove_header<'a, N: ?Sized>(
&mut self,
name: &'a N,
) -> Option<HeaderValue>where
&'a N: 'a + AsHeaderName,
Remove all headers under the name
Sourcepub fn header_to_h1_wire(&self, buf: &mut impl BufMut)
pub fn header_to_h1_wire(&self, buf: &mut impl BufMut)
Write the header to the buf
in HTTP/1.1 wire format.
The header case will be preserved.
Sourcepub fn set_status(&mut self, status: impl TryInto<StatusCode>) -> Result<()>
pub fn set_status(&mut self, status: impl TryInto<StatusCode>) -> Result<()>
Set the status code
Sourcepub fn set_version(&mut self, version: Version)
pub fn set_version(&mut self, version: Version)
Set the HTTP version
Sourcepub fn set_reason_phrase(&mut self, reason_phrase: Option<&str>) -> Result<()>
pub fn set_reason_phrase(&mut self, reason_phrase: Option<&str>) -> Result<()>
Set the HTTP reason phase. If None
, a default reason phase will be used
Sourcepub fn get_reason_phrase(&self) -> Option<&str>
pub fn get_reason_phrase(&self) -> Option<&str>
Get the HTTP reason phase. If Self::set_reason_phrase() is never called
or set to None
, a default reason phase will be used
Sourcepub fn as_owned_parts(&self) -> RespParts
pub fn as_owned_parts(&self) -> RespParts
Clone self
into http::response::Parts.
Trait Implementations§
Source§impl AsRef<Parts> for ResponseHeader
impl AsRef<Parts> for ResponseHeader
Source§impl Clone for ResponseHeader
impl Clone for ResponseHeader
Source§impl Debug for ResponseHeader
impl Debug for ResponseHeader
Source§impl Deref for ResponseHeader
impl Deref for ResponseHeader
Source§impl From<Parts> for ResponseHeader
impl From<Parts> for ResponseHeader
Source§fn from(parts: RespParts) -> ResponseHeader
fn from(parts: RespParts) -> ResponseHeader
Source§impl From<ResponseHeader> for Parts
impl From<ResponseHeader> for Parts
Source§fn from(resp: ResponseHeader) -> RespParts
fn from(resp: ResponseHeader) -> RespParts
Auto Trait Implementations§
impl Freeze for ResponseHeader
impl !RefUnwindSafe for ResponseHeader
impl Send for ResponseHeader
impl Sync for ResponseHeader
impl Unpin for ResponseHeader
impl !UnwindSafe for ResponseHeader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)