pub struct Headers { /* private fields */ }
Expand description

Wrapper over the list of headers associated with a Request that we need in order to parse the request correctly and be able to respond to it.

The only Content-Types supported are text/plain and application/json, which are both in plain text actually and don’t influence our parsing process.

All the other possible header fields are not necessary in order to serve this connection and, thus, are not of interest to us. However, we still look for header fields that might invalidate our request as we don’t support the full set of HTTP/1.1 specification. Such header entries are “Transfer-Encoding: identity; q=0”, which means a compression algorithm is applied to the body of the request, or “Expect: 103-checkpoint”.

Implementations

Expects one header line and parses it, updating the header structure or returning an error if the header is invalid.

Errors

UnsupportedHeader is returned when the parsed header line is not of interest to us or when it is unrecognizable. InvalidHeader is returned when the parsed header is formatted incorrectly or suggests that the client is using HTTP features that we do not support in this implementation, which invalidates the request.

Examples
use dbs_uhttp::Headers;

let mut request_header = Headers::default();
assert!(request_header.parse_header_line(b"Content-Length: 24").is_ok());
assert!(request_header.parse_header_line(b"Content-Length: 24: 2").is_err());

Returns the content length of the body.

Returns true if the transfer encoding is chunked.

Returns true if the client is expecting the code 100.

Returns the Accept header MediaType.

Parses a byte slice into a Headers structure for a HTTP request.

The byte slice is expected to have the following format:
* Request Header Lines “<header_line> CRLF”- Optional
There can be any number of request headers, including none, followed by an extra sequence of Carriage Return and Line Feed. All header fields are parsed. However, only the ones present in the Headers struct are relevant to us and stored for future use.

Errors

The function returns InvalidHeader when parsing the byte stream fails.

Examples
use dbs_uhttp::Headers;

let request_headers = Headers::try_from(b"Content-Length: 55\r\n\r\n");

Accept header setter.

Insert a new custom header and value pair into the HashMap.

Returns the custom header HashMap.

Trait Implementations

Formats the value using the given formatter. Read more

By default Requests are created with no headers.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.