From 3d436c10b1dd99170007412dcda85eac9afab594 Mon Sep 17 00:00:00 2001 From: Bat Date: Wed, 18 Jul 2018 16:25:02 +0200 Subject: [PATCH] Accept more content types when making AP requests --- plume-common/src/activity_pub/mod.rs | 1 + plume-common/src/activity_pub/request.rs | 3 ++- plume-models/src/blogs.rs | 4 ++-- plume-models/src/users.rs | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/plume-common/src/activity_pub/mod.rs b/plume-common/src/activity_pub/mod.rs index 841335f3..2f5e068b 100644 --- a/plume-common/src/activity_pub/mod.rs +++ b/plume-common/src/activity_pub/mod.rs @@ -17,6 +17,7 @@ pub mod sign; pub const CONTEXT_URL: &'static str = "https://www.w3.org/ns/activitystreams"; pub const PUBLIC_VISIBILTY: &'static str = "https://www.w3.org/ns/activitystreams#Public"; +pub const AP_ACCEPT_HEADER: &'static str = "application/ld+json; profile=\"https://w3.org/ns/activitystreams\", application/ld+json;profile=\"https://w3.org/ns/activitystreams\", application/activity+json, application/ld+json"; pub fn context() -> serde_json::Value { json!([ diff --git a/plume-common/src/activity_pub/request.rs b/plume-common/src/activity_pub/request.rs index 401bb000..b00e0868 100644 --- a/plume-common/src/activity_pub/request.rs +++ b/plume-common/src/activity_pub/request.rs @@ -9,6 +9,7 @@ use std::{ time::SystemTime }; +use activity_pub::AP_ACCEPT_HEADER; use activity_pub::sign::Signer; const USER_AGENT: &'static str = "Plume/0.1.0"; @@ -25,7 +26,7 @@ pub fn headers() -> Headers { let mut headers = Headers::new(); headers.set(UserAgent::new(USER_AGENT)); headers.set(Date(SystemTime::now().into())); - headers.set(ContentType(Mime::from_str("application/activity+json").unwrap())); + headers.set(ContentType(Mime::from_str(AP_ACCEPT_HEADER).unwrap())); headers } diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs index 736a1fc0..1032f4d7 100644 --- a/plume-models/src/blogs.rs +++ b/plume-models/src/blogs.rs @@ -18,7 +18,7 @@ use webfinger::*; use {BASE_URL, USE_HTTPS}; use plume_common::activity_pub::{ - ApSignature, ActivityStream, Id, IntoId, PublicKey, + AP_ACCEPT_HEADER, ApSignature, ActivityStream, Id, IntoId, PublicKey, inbox::WithInbox, sign }; @@ -109,7 +109,7 @@ impl Blog { fn fetch_from_url(conn: &PgConnection, url: String) -> Option { let req = Client::new() .get(&url[..]) - .header(Accept(vec![qitem("application/activity+json".parse::().unwrap())])) + .header(Accept(vec![qitem(AP_ACCEPT_HEADER.parse::().unwrap())])) .send(); match req { Ok(mut res) => { diff --git a/plume-models/src/users.rs b/plume-models/src/users.rs index 333081e4..9d66d2c7 100644 --- a/plume-models/src/users.rs +++ b/plume-models/src/users.rs @@ -13,7 +13,7 @@ use openssl::{ sign }; use plume_common::activity_pub::{ - ActivityStream, Id, IntoId, ApSignature, PublicKey, + AP_ACCEPT_HEADER, ActivityStream, Id, IntoId, ApSignature, PublicKey, inbox::WithInbox, sign::{Signer, gen_keypair} }; @@ -155,7 +155,7 @@ impl User { fn fetch_from_url(conn: &PgConnection, url: String) -> Option { let req = Client::new() .get(&url[..]) - .header(Accept(vec![qitem("application/activity+json".parse::().unwrap())])) + .header(Accept(vec![qitem(AP_ACCEPT_HEADER.parse::().unwrap())])) .send(); match req { Ok(mut res) => {