mirror of
https://git.asonix.dog/asonix/relay.git
synced 2025-01-10 19:45:26 +00:00
Update to actix-web 4.0.0-beta.3
This commit is contained in:
parent
1c813d917b
commit
43227d9852
12 changed files with 212 additions and 501 deletions
634
Cargo.lock
generated
634
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
17
Cargo.toml
17
Cargo.toml
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "relay"
|
||||
description = "A simple activitypub relay"
|
||||
version = "0.2.5"
|
||||
version = "0.2.6"
|
||||
authors = ["asonix <asonix@asonix.dog>"]
|
||||
license-file = "LICENSE"
|
||||
readme = "README.md"
|
||||
|
@ -14,26 +14,25 @@ build = "src/build.rs"
|
|||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
actix-rt = "1.1.1"
|
||||
actix-web = { version = "3.3.2", default-features = false, features = ["rustls", "compress"] }
|
||||
actix-webfinger = "0.3.0"
|
||||
activitystreams = "0.7.0-alpha.9"
|
||||
actix-rt = "2.0.2"
|
||||
actix-web = { version = "4.0.0-beta.3", default-features = false, features = ["rustls", "compress"] }
|
||||
actix-webfinger = "0.4.0-beta.2"
|
||||
activitystreams = "0.7.0-alpha.10"
|
||||
activitystreams-ext = "0.1.0-alpha.2"
|
||||
ammonia = "3.1.0"
|
||||
async-mutex = "1.0.1"
|
||||
async-rwlock = "1.3.0"
|
||||
background-jobs = "0.8.0"
|
||||
background-jobs = "0.9.0"
|
||||
base64 = "0.13"
|
||||
chrono = "0.4.19"
|
||||
config = "0.10.1"
|
||||
dotenv = "0.15.0"
|
||||
env_logger = "0.8.2"
|
||||
futures = "0.3.4"
|
||||
http-signature-normalization-actix = { version = "0.4.0", default-features = false, features = ["sha-2"] }
|
||||
futures = "0.3.12"
|
||||
http-signature-normalization-actix = { version = "0.5.0-beta.1", default-features = false, features = ["sha-2"] }
|
||||
log = "0.4"
|
||||
lru = "0.6.0"
|
||||
mime = "0.3.16"
|
||||
num_cpus = "1.12"
|
||||
pretty_env_logger = "0.4.0"
|
||||
rand = "0.7"
|
||||
rsa = "0.3"
|
||||
|
|
|
@ -83,7 +83,7 @@ impl State {
|
|||
let mut rng = thread_rng();
|
||||
RSAPrivateKey::new(&mut rng, 4096)
|
||||
})
|
||||
.await?;
|
||||
.await??;
|
||||
|
||||
db.update_private_key(&key).await?;
|
||||
|
||||
|
|
|
@ -227,7 +227,7 @@ impl Db {
|
|||
{
|
||||
let inner = self.inner.clone();
|
||||
|
||||
let t = actix_web::web::block(move || (f)(&inner)).await?;
|
||||
let t = actix_web::web::block(move || (f)(&inner)).await??;
|
||||
|
||||
Ok(t)
|
||||
}
|
||||
|
|
16
src/error.rs
16
src/error.rs
|
@ -131,22 +131,16 @@ impl ResponseError for MyError {
|
|||
|
||||
fn error_response(&self) -> HttpResponse {
|
||||
HttpResponse::build(self.status_code())
|
||||
.header("Content-Type", "application/activity+json")
|
||||
.json(serde_json::json!({
|
||||
.insert_header(("Content-Type", "application/activity+json"))
|
||||
.json(&serde_json::json!({
|
||||
"error": self.to_string(),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<BlockingError<T>> for MyError
|
||||
where
|
||||
T: Into<MyError> + Debug,
|
||||
{
|
||||
fn from(e: BlockingError<T>) -> Self {
|
||||
match e {
|
||||
BlockingError::Error(e) => e.into(),
|
||||
BlockingError::Canceled => MyError::Canceled,
|
||||
}
|
||||
impl From<BlockingError> for MyError {
|
||||
fn from(_: BlockingError) -> Self {
|
||||
MyError::Canceled
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,13 +32,12 @@ impl ResponseError for DebugError {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S> Transform<S> for DebugPayload
|
||||
impl<S> Transform<S, ServiceRequest> for DebugPayload
|
||||
where
|
||||
S: Service<Request = ServiceRequest, Error = actix_web::Error>,
|
||||
S: Service<ServiceRequest, Error = actix_web::Error>,
|
||||
S::Future: 'static,
|
||||
S::Error: 'static,
|
||||
{
|
||||
type Request = S::Request;
|
||||
type Response = S::Response;
|
||||
type Error = S::Error;
|
||||
type InitError = ();
|
||||
|
@ -50,22 +49,21 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<S> Service for DebugPayloadMiddleware<S>
|
||||
impl<S> Service<ServiceRequest> for DebugPayloadMiddleware<S>
|
||||
where
|
||||
S: Service<Request = ServiceRequest, Error = actix_web::Error>,
|
||||
S: Service<ServiceRequest, Error = actix_web::Error>,
|
||||
S::Future: 'static,
|
||||
S::Error: '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.1.poll_ready(cx)
|
||||
}
|
||||
|
||||
fn call(&mut self, mut req: S::Request) -> Self::Future {
|
||||
fn call(&self, mut req: ServiceRequest) -> Self::Future {
|
||||
if self.0 && req.method() == Method::POST {
|
||||
let pl = req.take_payload();
|
||||
req.set_payload(Payload::Stream(Box::pin(once(
|
||||
|
|
|
@ -124,7 +124,7 @@ async fn do_verify(
|
|||
|
||||
Ok(()) as Result<(), MyError>
|
||||
})
|
||||
.await?;
|
||||
.await??;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -219,8 +219,8 @@ impl Requests {
|
|||
let client: Client = self.client.borrow().clone();
|
||||
let res = client
|
||||
.get(url)
|
||||
.header("Accept", accept)
|
||||
.set(Date(SystemTime::now().into()))
|
||||
.insert_header(("Accept", accept))
|
||||
.insert_header(Date(SystemTime::now().into()))
|
||||
.signature(
|
||||
self.config.clone(),
|
||||
self.key_id.clone(),
|
||||
|
@ -276,8 +276,8 @@ impl Requests {
|
|||
let client: Client = self.client.borrow().clone();
|
||||
let res = client
|
||||
.get(url)
|
||||
.header("Accept", "*/*")
|
||||
.set(Date(SystemTime::now().into()))
|
||||
.insert_header(("Accept", "*/*"))
|
||||
.insert_header(Date(SystemTime::now().into()))
|
||||
.signature(
|
||||
self.config.clone(),
|
||||
self.key_id.clone(),
|
||||
|
@ -346,9 +346,9 @@ impl Requests {
|
|||
let client: Client = self.client.borrow().clone();
|
||||
let res = client
|
||||
.post(inbox.as_str())
|
||||
.header("Accept", "application/activity+json")
|
||||
.header("Content-Type", "application/activity+json")
|
||||
.set(Date(SystemTime::now().into()))
|
||||
.insert_header(("Accept", "application/activity+json"))
|
||||
.insert_header(("Content-Type", "application/activity+json"))
|
||||
.insert_header(Date(SystemTime::now().into()))
|
||||
.signature_with_digest(
|
||||
self.config.clone(),
|
||||
self.key_id.clone(),
|
||||
|
|
|
@ -31,7 +31,7 @@ pub(crate) async fn route(
|
|||
|
||||
fn cached(content_type: String, bytes: web::Bytes) -> HttpResponse {
|
||||
HttpResponse::Ok()
|
||||
.set(CacheControl(vec![
|
||||
.insert_header(CacheControl(vec![
|
||||
CacheDirective::Public,
|
||||
CacheDirective::MaxAge(60 * 60 * 24),
|
||||
CacheDirective::Extension("immutable".to_owned(), None),
|
||||
|
|
|
@ -23,7 +23,7 @@ fn ok<T>(item: T) -> HttpResponse
|
|||
where
|
||||
T: Serialize,
|
||||
{
|
||||
HttpResponse::Ok().content_type(CONTENT_TYPE).json(item)
|
||||
HttpResponse::Ok().content_type(CONTENT_TYPE).json(&item)
|
||||
}
|
||||
|
||||
fn accepted<T>(item: T) -> HttpResponse
|
||||
|
@ -32,5 +32,5 @@ where
|
|||
{
|
||||
HttpResponse::Accepted()
|
||||
.content_type(CONTENT_TYPE)
|
||||
.json(item)
|
||||
.json(&item)
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ pub(crate) async fn well_known(config: web::Data<Config>) -> impl Responder {
|
|||
kind: None,
|
||||
}],
|
||||
})
|
||||
.with_header("Content-Type", "application/jrd+json")
|
||||
.with_header(("Content-Type", "application/jrd+json"))
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
|
|
|
@ -7,12 +7,12 @@ use actix_web::{
|
|||
pub(crate) async fn route(filename: web::Path<String>) -> HttpResponse {
|
||||
if let Some(data) = StaticFile::get(&filename.into_inner()) {
|
||||
HttpResponse::Ok()
|
||||
.set(CacheControl(vec![
|
||||
.insert_header(CacheControl(vec![
|
||||
CacheDirective::Public,
|
||||
CacheDirective::MaxAge(60 * 60 * 24),
|
||||
CacheDirective::Extension("immutable".to_owned(), None),
|
||||
]))
|
||||
.set(ContentType(data.mime.clone()))
|
||||
.insert_header(ContentType(data.mime.clone()))
|
||||
.body(data.content)
|
||||
} else {
|
||||
HttpResponse::NotFound()
|
||||
|
|
Loading…
Reference in a new issue