Correctly parse HTTP Accept headers
This commit is contained in:
@@ -17,7 +17,15 @@ 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 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/activity+json",
|
||||
"application/ld+json"
|
||||
]
|
||||
}
|
||||
|
||||
pub fn context() -> serde_json::Value {
|
||||
json!([
|
||||
|
||||
@@ -2,14 +2,14 @@ use base64;
|
||||
use openssl::hash::{Hasher, MessageDigest};
|
||||
use reqwest::{
|
||||
mime::Mime,
|
||||
header::{ContentType, Date, Headers, UserAgent}
|
||||
header::{Accept, Date, Headers, UserAgent, qitem}
|
||||
};
|
||||
use std::{
|
||||
str::FromStr,
|
||||
time::SystemTime
|
||||
};
|
||||
|
||||
use activity_pub::AP_ACCEPT_HEADER;
|
||||
use activity_pub::ap_accept_header;
|
||||
use activity_pub::sign::Signer;
|
||||
|
||||
const USER_AGENT: &'static str = "Plume/0.1.0";
|
||||
@@ -26,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(AP_ACCEPT_HEADER).unwrap()));
|
||||
headers.set(Accept(ap_accept_header().into_iter().map(|h| qitem(h.parse::<Mime>().expect("Invalid Content-Type"))).collect()));
|
||||
headers
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user