summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTyler Murphy <tylermurphy534@gmail.com>2023-02-13 22:41:09 -0500
committerTyler Murphy <tylermurphy534@gmail.com>2023-02-13 22:41:09 -0500
commitb6fbeb512405542af0aed11ca123b7ac8ee0b04d (patch)
tree8cd9a708af765c266c6810e78c68ae9003008030 /src
parentfix login redirect (diff)
downloadxssbook-b6fbeb512405542af0aed11ca123b7ac8ee0b04d.tar.gz
xssbook-b6fbeb512405542af0aed11ca123b7ac8ee0b04d.tar.bz2
xssbook-b6fbeb512405542af0aed11ca123b7ac8ee0b04d.zip
fix seo
Diffstat (limited to 'src')
-rw-r--r--src/public/file.rs4
-rw-r--r--src/public/mod.rs3
-rw-r--r--src/public/pages.rs15
-rw-r--r--src/types/extract.rs26
4 files changed, 43 insertions, 5 deletions
diff --git a/src/public/file.rs b/src/public/file.rs
index 88b45b8..b796bc0 100644
--- a/src/public/file.rs
+++ b/src/public/file.rs
@@ -31,6 +31,10 @@ pub async fn favicon() -> Response {
super::serve("/favicon.ico").await
}
+pub async fn robots() -> Response {
+ super::serve("/robots.txt").await
+}
+
#[derive(Deserialize)]
pub struct AvatarRequest {
user_id: u64,
diff --git a/src/public/mod.rs b/src/public/mod.rs
index 82c994d..76796ea 100644
--- a/src/public/mod.rs
+++ b/src/public/mod.rs
@@ -35,6 +35,7 @@ pub fn router() -> Router {
Router::new()
.nest("/", pages::router())
.route("/favicon.ico", get(file::favicon))
+ .route("/robots.txt", get(file::robots))
.route("/js/*path", get(file::js))
.route("/css/*path", get(file::css))
.route("/fonts/*path", get(file::fonts))
@@ -71,7 +72,7 @@ pub async fn serve(path: &str) -> Response {
res.headers_mut().insert(
HeaderName::from_static("cache-control"),
- HeaderValue::from_static("public max-age=300"),
+ HeaderValue::from_static("max-age=300"),
);
res.into_response()
diff --git a/src/public/pages.rs b/src/public/pages.rs
index 32056b7..6d5c0de 100644
--- a/src/public/pages.rs
+++ b/src/public/pages.rs
@@ -1,13 +1,12 @@
use axum::{
response::{IntoResponse, Redirect, Response},
- routing::get,
- Router,
+ routing::get, Router
};
use crate::{
public::console,
types::{
- extract::{AuthorizedUser, Log},
+ extract::{AuthorizedUser, Log, UserAgent},
http::ResponseCode,
},
};
@@ -58,6 +57,15 @@ async fn wordpress(_: Log) -> Response {
ResponseCode::ImATeapot.text("Hello i am a teapot owo")
}
+async fn forgot(UserAgent(agent): UserAgent, _: Log) -> Response {
+
+ if agent.starts_with("curl") {
+ return super::serve("/404.html").await
+ }
+
+ Redirect::to("https://www.youtube.com/watch?v=dQw4w9WgXcQ").into_response()
+}
+
pub fn router() -> Router {
Router::new()
.route("/", get(root))
@@ -69,4 +77,5 @@ pub fn router() -> Router {
.route("/wp-admin", get(wordpress))
.route("/admin", get(admin))
.route("/docs", get(api))
+ .route("/forgot", get(forgot))
}
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,