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. Mutable access to the underlying parts is intentionally not provided because header mutations must use methods on ResponseHeader to preserve its internal state.
use pingora_http::ResponseHeader;
let mut response = ResponseHeader::build(200, None).unwrap();
response.headers.remove("server");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 case_header_iter(
&self,
) -> impl Iterator<Item = (&CaseHeaderName, &HeaderValue)> + '_
pub fn case_header_iter( &self, ) -> impl Iterator<Item = (&CaseHeaderName, &HeaderValue)> + '_
If case sensitivity is enabled, returns an iterator to iterate over case-sensitive header names and values. Otherwise returns an empty iterator.
Headers of the same name are visited in insertion order.
pub fn map<F: FnMut(HeaderNameVariant<'_>, &HeaderValue) -> Result<()>>( &self, f: F, ) -> Result<()>
Sourcepub fn extensions_mut(&mut self) -> &mut Extensions
pub fn extensions_mut(&mut self) -> &mut Extensions
Return mutable access to the response extensions.
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.
Sourcepub fn set_content_length(&mut self, len: usize) -> Result<()>
pub fn set_content_length(&mut self, len: usize) -> Result<()>
Helper function to set the HTTP content length on the response header.