Trait noggin::HeadParser

source ·
pub trait HeadParser<'de>: Sized {
    // Required method
    fn parse_head_section(head: &'de str) -> Result<Self, Error>;

    // Provided method
    fn parse_headers(
        head_and_body: &'de [u8]
    ) -> Result<(Self, &'de [u8]), Error> { ... }
}
Expand description

The HeadParser trait provides a way to parse HTTP headers and potentially returns the parsed headers and the remaining body of an HTTP message.

This trait is intended to be automatically implemented by the noggin::Noggin procedural macro for suitable structs. As such, users shouldn’t typically need to implement it manually.

Required Methods§

source

fn parse_head_section(head: &'de str) -> Result<Self, Error>

Parse the HTTP headers from a string slice representing the head section of an HTTP message.

Parameters
  • head: A string slice containing the head section of an HTTP message.
Returns
  • Result<Self, Error>: Returns the parsed headers if successful, or an error if parsing fails.

Provided Methods§

source

fn parse_headers(head_and_body: &'de [u8]) -> Result<(Self, &'de [u8]), Error>

Parse the HTTP headers and returns both the parsed headers and the remaining body from a byte slice containing both head and body sections of an HTTP message.

This function first locates the boundary between the head and body sections (denoted by the sequence \r\n\r\n), then validates the ASCII nature of the head, and finally calls the parse_head_section function to parse the headers.

Parameters
  • head_and_body: A byte slice containing both the head and body sections of an HTTP message.
Returns
  • Result<(Self, &'de [u8]), Error>: Returns a tuple containing the parsed headers and the remaining body if successful, or an error if parsing fails.

Object Safety§

This trait is not object safe.

Implementors§