feat(apb): introduce content-type constants
This commit is contained in:
parent
908662628b
commit
d8c416d1d9
5 changed files with 21 additions and 5 deletions
|
@ -1,5 +1,21 @@
|
|||
use crate::Object;
|
||||
|
||||
/// recommended content-type header value for AP fetches and responses
|
||||
pub const CONTENT_TYPE_LD_JSON_ACTIVITYPUB: &str = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"";
|
||||
/// alternative content-type header value for AP fetches and responses
|
||||
pub const CONTENT_TYPE_ACTIVITY_JSON: &str = "application/activity+json";
|
||||
/// uncommon and not officially supported content-type header value for AP fetches and responses
|
||||
#[deprecated = "use CONTENT_TYPE_LD_JSON_ACTIVITYPUB: 'application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"'"]
|
||||
pub const CONTENT_TYPE_LD_JSON: &str = "application/ld+json";
|
||||
|
||||
#[allow(deprecated)]
|
||||
pub fn is_activity_pub_content_type<T: AsRef<str>>(txt: T) -> bool {
|
||||
let r = txt.as_ref();
|
||||
r == CONTENT_TYPE_LD_JSON_ACTIVITYPUB
|
||||
|| r == CONTENT_TYPE_ACTIVITY_JSON
|
||||
|| r == CONTENT_TYPE_LD_JSON
|
||||
}
|
||||
|
||||
pub trait LD {
|
||||
fn ld_context(self) -> Self;
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ pub mod shortcuts;
|
|||
pub use shortcuts::Shortcuts;
|
||||
|
||||
#[cfg(feature = "jsonld")]
|
||||
mod jsonld;
|
||||
pub mod jsonld;
|
||||
|
||||
#[cfg(feature = "jsonld")]
|
||||
pub use jsonld::LD;
|
||||
|
|
|
@ -146,8 +146,8 @@ pub trait Fetcher {
|
|||
|
||||
let response = Self::client(domain)
|
||||
.request(method, url)
|
||||
.header(ACCEPT, "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")
|
||||
.header(CONTENT_TYPE, "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")
|
||||
.header(ACCEPT, apb::jsonld::CONTENT_TYPE_LD_JSON_ACTIVITYPUB)
|
||||
.header(CONTENT_TYPE, apb::jsonld::CONTENT_TYPE_LD_JSON_ACTIVITYPUB)
|
||||
.header("Host", host.clone())
|
||||
.header("Date", date.clone())
|
||||
.header("Digest", digest)
|
||||
|
|
|
@ -145,7 +145,7 @@ pub async fn webfinger(
|
|||
links: vec![
|
||||
JsonResourceDescriptorLink {
|
||||
rel: "self".to_string(),
|
||||
link_type: Some("application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"".to_string()),
|
||||
link_type: Some(apb::jsonld::CONTENT_TYPE_LD_JSON_ACTIVITYPUB.to_string()),
|
||||
href: Some(user.id),
|
||||
properties: jrd::Map::default(),
|
||||
titles: jrd::Map::default(),
|
||||
|
|
|
@ -39,7 +39,7 @@ pub struct JsonLD<T>(pub T);
|
|||
impl<T: serde::Serialize> IntoResponse for JsonLD<T> {
|
||||
fn into_response(self) -> Response {
|
||||
(
|
||||
[("Content-Type", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")],
|
||||
[("Content-Type", apb::jsonld::CONTENT_TYPE_LD_JSON_ACTIVITYPUB)],
|
||||
axum::Json(self.0)
|
||||
).into_response()
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue