Expand description
User-Agent (see also rama-ua
) http layer support
§Example
use rama_http::{
service::client::HttpClientExt, IntoResponse, Request, Response, StatusCode,
layer::ua::{PlatformKind, UserAgent, UserAgentClassifierLayer, UserAgentKind, UserAgentInfo},
};
use rama_core::{Context, Layer, service::service_fn};
use std::convert::Infallible;
const UA: &str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.2478.67";
async fn handle<S>(ctx: Context<S>, _req: Request) -> Result<Response, Infallible> {
let ua: &UserAgent = ctx.get().unwrap();
assert_eq!(ua.header_str(), UA);
assert_eq!(ua.info(), Some(UserAgentInfo{ kind: UserAgentKind::Chromium, version: Some(124) }));
assert_eq!(ua.platform(), Some(PlatformKind::Windows));
Ok(StatusCode::OK.into_response())
}
let service = UserAgentClassifierLayer::new().layer(service_fn(handle));
let _ = service
.get("http://www.example.com")
.typed_header(headers::UserAgent::from_static(UA))
.send(Context::default())
.await
.unwrap();
Structs§
- User
Agent - User Agent (UA) information.
- User
Agent Classifier - A
Service
that classifies theUserAgent
of incomingRequest
s. - User
Agent Classifier Layer - A
Layer
that wraps aService
with aUserAgentClassifier
. - User
Agent Info - Information about the
UserAgent
- User
Agent Overwrites - Information that can be used to overwrite the
UserAgent
of an http request.
Enums§
- Device
Kind - Device on which the
UserAgent
operates. - Http
Agent - Http implementation used by the
UserAgent
- Platform
Kind - Platform within the
UserAgent
operates. - TlsAgent
- Tls implementation used by the
UserAgent
- User
Agent Kind - The kind of
UserAgent