# Headers
Sometimes you need to inspect HTTP headers directly, such as for custom authentication tokens or client metadata. Actix Web provides multiple ways to access headers.
#Using HttpRequest
The most straightforward way is to extract the HttpRequest object, which contains all the headers.
code_blocksrust
use actix_web::{get, HttpRequest, HttpResponse};
#[get("/headers")]
async fn get_headers(req: HttpRequest) -> HttpResponse {
if let Some(user_agent) = req.headers().get("User-Agent") {
HttpResponse::Ok().body(format!("You are using: {:?}", user_agent))
} else {
HttpResponse::Ok().body("No user agent found")
}
}#Typed Headers Extractor (via actix-web-lab)
For stricter typing, you can use typed header extractors provided by extensions or manually parse header values.