Update to actix-web 4.0.0-beta.3
This commit is contained in:
parent
6339e1d78a
commit
7494f41d67
891
Cargo.lock
generated
891
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -8,13 +8,13 @@ build = "src/build.rs"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
actix-web = { version = "3.3.2", features = ["rustls"] }
|
||||
actix-web = { version = "4.0.0-beta.3", features = ["rustls", "compress"] }
|
||||
anyhow = "1.0"
|
||||
bcrypt = "0.9"
|
||||
env_logger = "0.8.2"
|
||||
futures = "0.3"
|
||||
mime = "0.3"
|
||||
minify-html = "0.3.9"
|
||||
minify-html = "0.4.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
sled = { version = "0.34.6", features = ["zstd"] }
|
||||
|
|
|
@ -48,7 +48,7 @@ impl Connection {
|
|||
let client_request = self.client.request_from(self.upload_url(), req.head());
|
||||
|
||||
let client_request = if let Some(addr) = req.head().peer_addr {
|
||||
client_request.header("X-Forwarded-For", addr.to_string())
|
||||
client_request.append_header(("X-Forwarded-For", addr.to_string()))
|
||||
} else {
|
||||
client_request
|
||||
};
|
||||
|
@ -114,7 +114,7 @@ impl Connection {
|
|||
) -> Result<HttpResponse, actix_web::Error> {
|
||||
let client_request = self.client.request_from(url, req.head());
|
||||
let client_request = if let Some(addr) = req.head().peer_addr {
|
||||
client_request.header("X-Forwarded-For", addr.to_string())
|
||||
client_request.append_header(("X-Forwarded-For", addr.to_string()))
|
||||
} else {
|
||||
client_request
|
||||
};
|
||||
|
@ -124,7 +124,7 @@ impl Connection {
|
|||
let mut client_res = HttpResponse::build(res.status());
|
||||
|
||||
for (name, value) in res.headers().iter().filter(|(h, _)| *h != "connection") {
|
||||
client_res.header(name.clone(), value.clone());
|
||||
client_res.append_header((name.clone(), value.clone()));
|
||||
}
|
||||
|
||||
Ok(client_res.body(BodyStream::new(res)))
|
||||
|
|
20
src/lib.rs
20
src/lib.rs
|
@ -212,19 +212,19 @@ pub fn service(client: Client, state: State) -> Scope {
|
|||
|
||||
fn to_edit_page(id: Uuid, token: &ValidToken, state: &State) -> HttpResponse {
|
||||
HttpResponse::SeeOther()
|
||||
.header(LOCATION, state.edit_collection_path(id, token))
|
||||
.insert_header((LOCATION, state.edit_collection_path(id, token)))
|
||||
.finish()
|
||||
}
|
||||
|
||||
fn to_404(state: &State) -> HttpResponse {
|
||||
HttpResponse::MovedPermanently()
|
||||
.header(LOCATION, state.create_collection_path())
|
||||
.insert_header((LOCATION, state.create_collection_path()))
|
||||
.finish()
|
||||
}
|
||||
|
||||
fn to_home(state: &State) -> HttpResponse {
|
||||
HttpResponse::SeeOther()
|
||||
.header(LOCATION, state.create_collection_path())
|
||||
.insert_header((LOCATION, state.create_collection_path()))
|
||||
.finish()
|
||||
}
|
||||
|
||||
|
@ -249,13 +249,13 @@ async fn static_files(filename: web::Path<String>, state: web::Data<State>) -> H
|
|||
|
||||
if let Some(data) = self::templates::statics::StaticFile::get(&filename) {
|
||||
return HttpResponse::Ok()
|
||||
.set(LastModified(state.startup.into()))
|
||||
.set(CacheControl(vec![
|
||||
.insert_header(LastModified(state.startup.into()))
|
||||
.insert_header(CacheControl(vec![
|
||||
CacheDirective::Public,
|
||||
CacheDirective::MaxAge(365 * DAYS),
|
||||
CacheDirective::Extension("immutable".to_owned(), None),
|
||||
]))
|
||||
.set(ContentType(data.mime.clone()))
|
||||
.insert_header(ContentType(data.mime.clone()))
|
||||
.body(data.content);
|
||||
}
|
||||
|
||||
|
@ -731,7 +731,13 @@ fn rendered(
|
|||
let mut cursor = Cursor::new(vec![]);
|
||||
(f)(&mut cursor)?;
|
||||
let mut html = cursor.into_inner();
|
||||
let len = minify_html::in_place(&mut html, &minify_html::Cfg { minify_js: true })?;
|
||||
let len = minify_html::in_place(
|
||||
&mut html,
|
||||
&minify_html::Cfg {
|
||||
minify_js: true,
|
||||
minify_css: true,
|
||||
},
|
||||
)?;
|
||||
html.truncate(len);
|
||||
|
||||
Ok(builder
|
||||
|
|
|
@ -64,12 +64,11 @@ impl ResponseError for VerifyError {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S> Transform<S> for Verify
|
||||
impl<S> Transform<S, ServiceRequest> for Verify
|
||||
where
|
||||
S: Service<Request = ServiceRequest, Error = actix_web::Error>,
|
||||
S: Service<ServiceRequest, Error = actix_web::Error>,
|
||||
S::Future: 'static,
|
||||
{
|
||||
type Request = S::Request;
|
||||
type Response = S::Response;
|
||||
type Error = S::Error;
|
||||
type InitError = ();
|
||||
|
@ -81,30 +80,27 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<S> Service for VerifyMiddleware<S>
|
||||
impl<S> Service<ServiceRequest> for VerifyMiddleware<S>
|
||||
where
|
||||
S: Service<Request = ServiceRequest, Error = actix_web::Error>,
|
||||
S: Service<ServiceRequest, Error = actix_web::Error>,
|
||||
S::Future: 'static,
|
||||
{
|
||||
type Request = S::Request;
|
||||
type Response = S::Response;
|
||||
type Error = S::Error;
|
||||
type Future = LocalBoxFuture<'static, Result<S::Response, S::Error>>;
|
||||
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
self.0.poll_ready(cx)
|
||||
}
|
||||
|
||||
fn call(&mut self, req: S::Request) -> Self::Future {
|
||||
fn call(&self, req: ServiceRequest) -> Self::Future {
|
||||
let (req, pl) = req.into_parts();
|
||||
|
||||
let state_fut = web::Data::<crate::State>::extract(&req);
|
||||
let token_fut = Option::<web::Query<crate::Token>>::extract(&req);
|
||||
let path_fut = web::Path::<crate::CollectionPath>::extract(&req);
|
||||
|
||||
let req = ServiceRequest::from_parts(req, pl)
|
||||
.map_err(|_| VerifyError)
|
||||
.unwrap();
|
||||
let req = ServiceRequest::from_parts(req, pl);
|
||||
|
||||
let (tx, rx) = oneshot::channel();
|
||||
|
||||
|
@ -149,6 +145,7 @@ async fn verify(
|
|||
|
||||
let verified = web::block(move || token_storage.verify(&token))
|
||||
.await
|
||||
.map_err(|_| VerifyError)?
|
||||
.map_err(|_| VerifyError)?;
|
||||
|
||||
if !verified {
|
||||
|
|
35
src/store.rs
35
src/store.rs
|
@ -87,7 +87,7 @@ impl Store {
|
|||
|
||||
let token_key = config.collection_path.token_key();
|
||||
let token2 = config.token.clone();
|
||||
let token_value = serde_json::to_string(&web::block(move || token2.hash()).await?)?;
|
||||
let token_value = serde_json::to_string(&web::block(move || token2.hash()).await??)?;
|
||||
|
||||
let tree = self.tree.clone();
|
||||
|
||||
|
@ -98,7 +98,7 @@ impl Store {
|
|||
Ok(())
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
.await??;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ impl Store {
|
|||
let tree = self.tree.clone();
|
||||
|
||||
web::block(move || tree.insert(collection_key.as_bytes(), collection_value.as_bytes()))
|
||||
.await?;
|
||||
.await??;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ impl Store {
|
|||
|
||||
Ok(()) as Result<(), Error>
|
||||
})
|
||||
.await?;
|
||||
.await??;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ impl Store {
|
|||
|
||||
let tree = self.tree.clone();
|
||||
|
||||
web::block(move || tree.insert(entry_key.as_bytes(), entry_value.as_bytes())).await?;
|
||||
web::block(move || tree.insert(entry_key.as_bytes(), entry_value.as_bytes())).await??;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ impl Store {
|
|||
|
||||
let tree = self.tree.clone();
|
||||
|
||||
web::block(move || tree.insert(entry_key.as_bytes(), entry_value.as_bytes())).await?;
|
||||
web::block(move || tree.insert(entry_key.as_bytes(), entry_value.as_bytes())).await??;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ impl Store {
|
|||
let entry_key = config.entry_path.key();
|
||||
let tree = self.tree.clone();
|
||||
|
||||
web::block(move || tree.remove(entry_key)).await?;
|
||||
web::block(move || tree.remove(entry_key)).await??;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ impl Store {
|
|||
let collection_key = path.key();
|
||||
let tree = self.tree.clone();
|
||||
|
||||
let opt = web::block(move || tree.get(collection_key.as_bytes())).await?;
|
||||
let opt = web::block(move || tree.get(collection_key.as_bytes())).await??;
|
||||
|
||||
match opt {
|
||||
Some(a) => {
|
||||
|
@ -197,7 +197,7 @@ impl Store {
|
|||
let entry_key = path.key();
|
||||
let tree = self.tree.clone();
|
||||
|
||||
let opt = web::block(move || tree.get(entry_key.as_bytes())).await?;
|
||||
let opt = web::block(move || tree.get(entry_key.as_bytes())).await??;
|
||||
|
||||
match opt {
|
||||
Some(e) => {
|
||||
|
@ -227,7 +227,7 @@ impl Store {
|
|||
})
|
||||
.collect::<Result<Vec<_>, Error>>()
|
||||
})
|
||||
.await?;
|
||||
.await??;
|
||||
|
||||
Ok(v)
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ impl Store {
|
|||
let token_key = path.token_key();
|
||||
let tree = self.tree.clone();
|
||||
|
||||
let token_opt = web::block(move || tree.get(token_key.as_bytes())).await?;
|
||||
let token_opt = web::block(move || tree.get(token_key.as_bytes())).await??;
|
||||
|
||||
match token_opt {
|
||||
Some(token_ivec) => {
|
||||
|
@ -272,15 +272,8 @@ pub(crate) enum Error {
|
|||
Blocking,
|
||||
}
|
||||
|
||||
impl<E> From<actix_web::error::BlockingError<E>> for Error
|
||||
where
|
||||
E: std::fmt::Debug,
|
||||
Error: From<E>,
|
||||
{
|
||||
fn from(err: actix_web::error::BlockingError<E>) -> Self {
|
||||
match err {
|
||||
actix_web::error::BlockingError::Error(e) => e.into(),
|
||||
_ => Error::Blocking,
|
||||
}
|
||||
impl From<actix_web::error::BlockingError> for Error {
|
||||
fn from(_: actix_web::error::BlockingError) -> Self {
|
||||
Error::Blocking
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue