From 4d19861a25a19395c529dbc3830fecfdf37130a1 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Wed, 4 May 2022 01:56:49 +0900 Subject: [PATCH 1/7] Fix accept header --- plume-common/src/activity_pub/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plume-common/src/activity_pub/mod.rs b/plume-common/src/activity_pub/mod.rs index 23b2b5f4..74283abd 100644 --- a/plume-common/src/activity_pub/mod.rs +++ b/plume-common/src/activity_pub/mod.rs @@ -24,8 +24,8 @@ pub const AP_CONTENT_TYPE: &str = pub fn ap_accept_header() -> Vec<&'static str> { vec![ - "application/ld+json; profile=\"https://w3.org/ns/activitystreams\"", - "application/ld+json;profile=\"https://w3.org/ns/activitystreams\"", + "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"", + "application/ld+json;profile=\"https://www.w3.org/ns/activitystreams\"", "application/activity+json", "application/ld+json", ] From 45a6744d4d84da1fb6b160ea3582a2787f919d2c Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Wed, 4 May 2022 01:58:44 +0900 Subject: [PATCH 2/7] [skip ci]Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18552e09..de314b9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Add explanation of sign-up step at sign-up page when email sign-up mode (#1012) - Add NOT NULL constraint to email_blocklist table fields (#1016) - Don't fill empty content when switching rich editor (#1017) +- Fix accept header (#1058) ## [[0.7.1]] - 2022-01-12 From 073b72c9ed74fa7ff5aebb3c9eae63e920129824 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Wed, 4 May 2022 02:01:58 +0900 Subject: [PATCH 3/7] Add more fixes --- plume-common/src/activity_pub/mod.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plume-common/src/activity_pub/mod.rs b/plume-common/src/activity_pub/mod.rs index 74283abd..e04106ce 100644 --- a/plume-common/src/activity_pub/mod.rs +++ b/plume-common/src/activity_pub/mod.rs @@ -87,14 +87,16 @@ impl<'a, 'r> FromRequest<'a, 'r> for ApRequest { .map(|header| { header .split(',') - .map(|ct| match ct.trim() { + .map(|ct| { + match ct.trim() { // bool for Forward: true if found a valid Content-Type for Plume first (HTML), false otherwise - "application/ld+json; profile=\"https://w3.org/ns/activitystreams\"" - | "application/ld+json;profile=\"https://w3.org/ns/activitystreams\"" + "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"" + | "application/ld+json;profile=\"https://www.w3.org/ns/activitystreams\"" | "application/activity+json" | "application/ld+json" => Outcome::Success(ApRequest), "text/html" => Outcome::Forward(true), _ => Outcome::Forward(false), + } }) .fold(Outcome::Forward(false), |out, ct| { if out.clone().forwarded().unwrap_or_else(|| out.is_success()) { From db0f1a3c46665f28068aa9d1288aa7a8a0a595a8 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Wed, 4 May 2022 04:22:50 +0900 Subject: [PATCH 4/7] Reuse reqwest client on broadcasting See https://users.rust-lang.org/t/reqwest-http-client-fails-when-too-much-concurrency/55644/2 --- plume-common/src/activity_pub/mod.rs | 55 ++++++++++++++-------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/plume-common/src/activity_pub/mod.rs b/plume-common/src/activity_pub/mod.rs index e04106ce..1f9ba23b 100644 --- a/plume-common/src/activity_pub/mod.rs +++ b/plume-common/src/activity_pub/mod.rs @@ -132,6 +132,14 @@ where .sign(sender) .expect("activity_pub::broadcast: signature error"); + let client = if let Some(proxy) = proxy.clone() { + ClientBuilder::new().proxy(proxy) + } else { + ClientBuilder::new() + } + .connect_timeout(std::time::Duration::from_secs(5)) + .build() + .expect("Can't build client"); let mut rt = tokio::runtime::current_thread::Runtime::new() .expect("Error while initializing tokio runtime for federation"); for inbox in boxes { @@ -155,33 +163,26 @@ where headers.insert("Host", host_header_value.unwrap()); headers.insert("Digest", request::Digest::digest(&body)); rt.spawn( - if let Some(proxy) = proxy.clone() { - ClientBuilder::new().proxy(proxy) - } else { - ClientBuilder::new() - } - .connect_timeout(std::time::Duration::from_secs(5)) - .build() - .expect("Can't build client") - .post(&inbox) - .headers(headers.clone()) - .header( - "Signature", - request::signature(sender, &headers, ("post", url.path(), url.query())) - .expect("activity_pub::broadcast: request signature error"), - ) - .body(body) - .send() - .and_then(move |r| { - if r.status().is_success() { - debug!("Successfully sent activity to inbox ({})", &inbox); - } else { - warn!("Error while sending to inbox ({:?})", &r) - } - r.into_body().concat2() - }) - .map(move |response| debug!("Response: \"{:?}\"\n", response)) - .map_err(|e| warn!("Error while sending to inbox ({:?})", e)), + client + .post(&inbox) + .headers(headers.clone()) + .header( + "Signature", + request::signature(sender, &headers, ("post", url.path(), url.query())) + .expect("activity_pub::broadcast: request signature error"), + ) + .body(body) + .send() + .and_then(move |r| { + if r.status().is_success() { + debug!("Successfully sent activity to inbox ({})", &inbox); + } else { + warn!("Error while sending to inbox ({:?})", &r) + } + r.into_body().concat2() + }) + .map(move |response| debug!("Response: \"{:?}\"\n", response)) + .map_err(|e| warn!("Error while sending to inbox ({:?})", e)), ); } rt.run().unwrap(); From 889decc72018d64fe43b31261624270dfbe4af9e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 May 2022 19:24:10 +0000 Subject: [PATCH 5/7] Bump validator from 0.14.0 to 0.15.0 Bumps [validator](https://github.com/Keats/validator) from 0.14.0 to 0.15.0. - [Release notes](https://github.com/Keats/validator/releases) - [Changelog](https://github.com/Keats/validator/blob/master/CHANGELOG.md) - [Commits](https://github.com/Keats/validator/compare/v0.14.0...v0.15.0) --- updated-dependencies: - dependency-name: validator dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Cargo.lock | 25 ++++++++++++------------- Cargo.toml | 2 +- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2828a846..51ebe624 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -144,9 +144,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.15" +version = "0.7.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" dependencies = [ "memchr", ] @@ -2373,9 +2373,9 @@ checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771" [[package]] name = "memchr" -version = "2.3.4" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memmap" @@ -3685,9 +3685,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.4.6" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a26af418b574bd56588335b3a3659a65725d4e636eb1016c2f9e3b38c7cc759" +checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286" dependencies = [ "aho-corasick", "memchr", @@ -5270,9 +5270,9 @@ dependencies = [ [[package]] name = "validator" -version = "0.14.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d0f08911ab0fee2c5009580f04615fa868898ee57de10692a45da0c3bcc3e5e" +checksum = "f07b0a1390e01c0fc35ebb26b28ced33c9a3808f7f9fbe94d3cc01e233bfeed5" dependencies = [ "idna 0.2.3", "lazy_static", @@ -5282,14 +5282,13 @@ dependencies = [ "serde_json", "url 2.2.2", "validator_derive", - "validator_types", ] [[package]] name = "validator_derive" -version = "0.14.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d85135714dba11a1bd0b3eb1744169266f1a38977bf4e3ff5e2e1acb8c2b7eee" +checksum = "ea7ed5e8cf2b6bdd64a6c4ce851da25388a89327b17b88424ceced6bd5017923" dependencies = [ "if_chain", "lazy_static", @@ -5303,9 +5302,9 @@ dependencies = [ [[package]] name = "validator_types" -version = "0.14.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded9d97e1d42327632f5f3bae6403c04886e2de3036261ef42deebd931a6a291" +checksum = "d2ddf34293296847abfc1493b15c6e2f5d3cd19f57ad7d22673bf4c6278da329" dependencies = [ "proc-macro2 1.0.36", "syn 1.0.92", diff --git a/Cargo.toml b/Cargo.toml index ad0ed9aa..72f3b9c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ scheduled-thread-pool = "0.2.2" serde = "1.0" serde_json = "1.0.80" shrinkwraprs = "0.3.0" -validator = { version = "0.14", features = ["derive"] } +validator = { version = "0.15", features = ["derive"] } webfinger = "0.4.1" tracing = "0.1.34" tracing-subscriber = "0.3.10" From 4529b929d824fcf5bd46250761f01e9c335cae3b Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Wed, 4 May 2022 04:26:47 +0900 Subject: [PATCH 6/7] [skip ci]Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index de314b9e..df7324a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - Add NOT NULL constraint to email_blocklist table fields (#1016) - Don't fill empty content when switching rich editor (#1017) - Fix accept header (#1058) +- Reuse reqwest client on broadcasting (#1059) ## [[0.7.1]] - 2022-01-12 From 040452890824b6177cc9b6d17daeeb3bdac80014 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Wed, 4 May 2022 04:40:16 +0900 Subject: [PATCH 7/7] Remove unnecessary clone of config --- plume-common/src/activity_pub/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plume-common/src/activity_pub/mod.rs b/plume-common/src/activity_pub/mod.rs index 1f9ba23b..bd640f10 100644 --- a/plume-common/src/activity_pub/mod.rs +++ b/plume-common/src/activity_pub/mod.rs @@ -132,7 +132,7 @@ where .sign(sender) .expect("activity_pub::broadcast: signature error"); - let client = if let Some(proxy) = proxy.clone() { + let client = if let Some(proxy) = proxy { ClientBuilder::new().proxy(proxy) } else { ClientBuilder::new()