diff options
author | Tyler Murphy <tylermurphy534@gmail.com> | 2023-02-13 22:41:09 -0500 |
---|---|---|
committer | Tyler Murphy <tylermurphy534@gmail.com> | 2023-02-13 22:41:09 -0500 |
commit | b6fbeb512405542af0aed11ca123b7ac8ee0b04d (patch) | |
tree | 8cd9a708af765c266c6810e78c68ae9003008030 /src/types | |
parent | fix login redirect (diff) | |
download | xssbook-b6fbeb512405542af0aed11ca123b7ac8ee0b04d.tar.gz xssbook-b6fbeb512405542af0aed11ca123b7ac8ee0b04d.tar.bz2 xssbook-b6fbeb512405542af0aed11ca123b7ac8ee0b04d.zip |
fix seo
Diffstat (limited to 'src/types')
-rw-r--r-- | src/types/extract.rs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/types/extract.rs b/src/types/extract.rs index 8292da7..6a01ad2 100644 --- a/src/types/extract.rs +++ b/src/types/extract.rs @@ -7,7 +7,7 @@ use axum::{ async_trait, body::HttpBody, extract::{ConnectInfo, FromRequest, FromRequestParts}, - http::{request::Parts, Request}, + http::{request::Parts, Request, header::USER_AGENT}, response::Response, BoxError, RequestExt, }; @@ -236,6 +236,30 @@ pub trait Check { } } +pub struct UserAgent(pub String); + +#[async_trait] +impl<S> FromRequestParts<S> for UserAgent +where + S: Send + Sync, +{ + type Rejection = Response; + + async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self> { + let agent = parts.headers.get(USER_AGENT); + + let Some(agent) = agent else { + return Err(ResponseCode::BadRequest.text("Bad Request")); + }; + + let Ok(agent) = agent.to_str() else { + return Err(ResponseCode::BadRequest.text("Bad Request")); + }; + + Ok(UserAgent(agent.to_string())) + } +} + async fn read_body<S, B>(mut req: Request<B>, state: &S) -> Result<Vec<u8>> where B: HttpBody + Sync + Send + 'static, |