Extracting data from HTTP request headers
In this section we will not implement full authentication, as this will be addressed in chapter 10, managing user sessions. Here we are just going to extract a string from the header.
When it comes to headers, we can store credentials, or metadata around the HTTP request. Before we get into inspecting headers of our HTTP requests, we must define our token in our glue
workspace because we are going to use the token for authentication in the future. Every service should have the right to enforce authentication without having to rewrite the token implementation.
We can start our token definition with the following imports:
//! File: glue/src/token.rs
#[cfg(feature = "actix")]
use actix_web::{
dev::Payload,
FromRequest,
HttpRequest,
};
#[cfg(feature = "actix")]
use futures::future::{Ready, ok, err};
#[cfg(feature = "actix")]
use crate::errors::{
NanoServiceError,
NanoServiceErrorStatus
};
We can...