summaryrefslogtreecommitdiff
path: root/src/types
diff options
context:
space:
mode:
authorTyler Murphy <tylermurphy534@gmail.com>2023-02-15 00:47:55 -0500
committerTyler Murphy <tylermurphy534@gmail.com>2023-02-15 00:47:55 -0500
commita8b6798dfe4939dc8c36cec6b36a4261477fb087 (patch)
tree57265c5c018da32c61bd8ebdf60d99129e35612a /src/types
parentmake database calls 1 conn (diff)
downloadxssbook-a8b6798dfe4939dc8c36cec6b36a4261477fb087.tar.gz
xssbook-a8b6798dfe4939dc8c36cec6b36a4261477fb087.tar.bz2
xssbook-a8b6798dfe4939dc8c36cec6b36a4261477fb087.zip
fix root db call
Diffstat (limited to 'src/types')
-rw-r--r--src/types/extract.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/types/extract.rs b/src/types/extract.rs
index f05215f..a76eac4 100644
--- a/src/types/extract.rs
+++ b/src/types/extract.rs
@@ -9,7 +9,7 @@ use axum::{
extract::{ConnectInfo, FromRequest, FromRequestParts},
http::{header::USER_AGENT, request::Parts, Request},
response::Response,
- BoxError, RequestExt,
+ BoxError, RequestExt, middleware::Next,
};
use bytes::Bytes;
use image::{io::Reader, DynamicImage, ImageFormat};
@@ -100,7 +100,7 @@ where
};
let Some(db) = parts.extensions.get::<DatabaseExtention>() else {
- return Err(ResponseCode::Forbidden.text("Could not connect to database"))
+ return Err(ResponseCode::InternalServerError.text("Could not connect to database"))
};
let db = db.0.lock().await;
@@ -288,6 +288,18 @@ where
}
}
+pub async fn connect<B>(mut req: Request<B>, next: Next<B>) -> Response
+where
+ B: Send,
+{
+ if let Ok(db) = database::Database::connect() {
+ let ex = DatabaseExtention(Mutex::new(db));
+ req.extensions_mut().insert(ex);
+ }
+
+ next.run(req).await
+}
+
async fn read_body<S, B>(mut req: Request<B>, state: &S) -> Result<Vec<u8>>
where
B: HttpBody + Sync + Send + 'static,