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