Skip to main content

HttpMessage

Trait HttpMessage 

Source
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§

Source

fn message_headers(&self) -> &HeaderMap

Returns the message headers.

Source

fn message_extensions(&self) -> Ref<'_, Extensions>

Returns the message extensions.

Source

fn message_extensions_mut(&self) -> RefMut<'_, Extensions>

Returns mutable access to the message extensions.

Provided Methods§

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn cookies(&self) -> Result<Ref<'_, Vec<Cookie<'static>>>, ParseError>

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.

Source

fn cookie(&self, name: &str) -> Option<Cookie<'static>>

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".

Implementors§