pub trait HttpMessage: Sized {
// Required methods
fn message_headers(&self) -> &HeaderMap;
fn message_extensions(&self) -> Ref<'_, Extensions>;
fn message_extensions_mut(&self) -> RefMut<'_, Extensions>;
// Provided methods
fn content_type(&self) -> &str { ... }
fn encoding(&self) -> Result<&'static Encoding, ContentTypeError> { ... }
fn mime_type(&self) -> Result<Option<Mime>, ContentTypeError> { ... }
fn chunked(&self) -> Result<bool, DecodeError> { ... }
fn cookies(&self) -> Result<Ref<'_, Vec<Cookie<'static>>>, ParseError> { ... }
fn cookie(&self, name: &str) -> Option<Cookie<'static>> { ... }
}Expand description
Common operations for HTTP requests and responses.
Required Methods§
Sourcefn message_headers(&self) -> &HeaderMap
fn message_headers(&self) -> &HeaderMap
Returns the message headers.
Sourcefn message_extensions(&self) -> Ref<'_, Extensions>
fn message_extensions(&self) -> Ref<'_, Extensions>
Returns the message extensions.
Sourcefn message_extensions_mut(&self) -> RefMut<'_, Extensions>
fn message_extensions_mut(&self) -> RefMut<'_, Extensions>
Returns mutable access to the message extensions.
Provided Methods§
Sourcefn content_type(&self) -> &str
fn content_type(&self) -> &str
Returns the media type from the Content-Type header.
Parameters such as charset are omitted. Returns an empty string when
the header is missing or is not valid UTF-8.
Sourcefn encoding(&self) -> Result<&'static Encoding, ContentTypeError>
fn encoding(&self) -> Result<&'static Encoding, ContentTypeError>
Returns the character encoding declared by Content-Type.
UTF-8 is returned when the header or its charset parameter is absent.
§Errors
Returns ContentTypeError::ParseError for an invalid media type or
ContentTypeError::UnknownEncoding for an unknown charset.
Sourcefn mime_type(&self) -> Result<Option<Mime>, ContentTypeError>
fn mime_type(&self) -> Result<Option<Mime>, ContentTypeError>
Parses the Content-Type header as a MIME type.
§Errors
Returns ContentTypeError::ParseError when the header is not valid
UTF-8 or does not contain a valid MIME value.
Sourcefn chunked(&self) -> Result<bool, DecodeError>
fn chunked(&self) -> Result<bool, DecodeError>
Returns whether Transfer-Encoding contains chunked.
§Errors
Returns DecodeError::Header when the header value is not valid
UTF-8.
Parses and caches cookies from the Cookie headers.
§Errors
Returns an error if a header is not valid UTF-8 or a cookie cannot be parsed.
Returns the first request cookie with the given name.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".