request_headers

Macro request_headers 

Source
request_headers!() { /* proc-macro */ }
Expand description

Extracts the request headers in an endpoint function.

The request_headers macro allows an endpoint function to access the HTTP request headers. It must be used as an attribute on a function parameter of type Headers.

§Usage

  • If headers need to be modified, the parameter should be mutable (mut).
  • The headers can be queried using methods from the Headers struct.

§Example

#[post( url = "/post_request_header_example" )]
fn post_request_header_example(
    #[request_headers]
    headers : Headers
) -> String
{
    match headers.get_value("content-type") {
        Some(c) => c,
        _ => "Content-Type not found".to_string()
    }
}