|
|
|
@ -14,12 +14,13 @@ use crate::state::AppState;
|
|
|
|
|
use bytes::Bytes;
|
|
|
|
|
use futures::future::{BoxFuture, FutureExt};
|
|
|
|
|
use hashbrown::HashSet;
|
|
|
|
|
use iref::{Iri, IriBuf};
|
|
|
|
|
use iref::Iri;
|
|
|
|
|
use json_ld::{
|
|
|
|
|
syntax::{Parse, Value},
|
|
|
|
|
Loader, Profile, RemoteDocument,
|
|
|
|
|
};
|
|
|
|
|
use locspan::{Meta, Span};
|
|
|
|
|
use rdf_types::vocabulary::IriIndex;
|
|
|
|
|
use rdf_types::{IriVocabulary, IriVocabularyMut};
|
|
|
|
|
use reqwest::{
|
|
|
|
|
header::{ACCEPT, CONTENT_TYPE, LINK, LOCATION},
|
|
|
|
@ -35,7 +36,7 @@ use crate::util::http::{
|
|
|
|
|
Response,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pub struct CachedLoader<I = IriBuf, M = Span, T = Value<M>> {
|
|
|
|
|
pub struct CachedLoader<I = IriIndex, M = Span, T = Value<M>> {
|
|
|
|
|
state: AppState,
|
|
|
|
|
parser: Box<DynParser<I, M, T>>,
|
|
|
|
|
}
|
|
|
|
@ -104,10 +105,13 @@ impl<I: Clone + Eq + Hash + Send + Sync, M: Send, T: Clone + Send> CachedLoader<
|
|
|
|
|
return Err(Error::NotFound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
debug!(target: "ap", "downloading {}", vocabulary.iri(&url).unwrap().as_str());
|
|
|
|
|
let iri = vocabulary
|
|
|
|
|
.iri(&url)
|
|
|
|
|
.ok_or_else(|| Error::MalformedApub(String::from("Unresolved IRI")))?;
|
|
|
|
|
debug!(target: "ap", "downloading {iri}");
|
|
|
|
|
let response = http::get(
|
|
|
|
|
&self.state,
|
|
|
|
|
vocabulary.iri(&url).unwrap().as_str(),
|
|
|
|
|
iri.as_str(),
|
|
|
|
|
headers! {
|
|
|
|
|
ACCEPT => ACCEPT_ACTIVITY_PUB,
|
|
|
|
|
},
|
|
|
|
@ -181,7 +185,7 @@ impl<I: Clone + Eq + Hash + Send + Sync, M: Send, T: Clone + Send> CachedLoader<
|
|
|
|
|
}
|
|
|
|
|
None => {
|
|
|
|
|
break Err(Error::MalformedApub(String::from(
|
|
|
|
|
"Missing Location leader in HTTP redirect",
|
|
|
|
|
"Missing Location header in HTTP redirect",
|
|
|
|
|
)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -215,8 +219,12 @@ impl<I: Clone + Eq + Hash + Send + Sync, M: Send, T: Clone + Send> CachedLoader<
|
|
|
|
|
)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let u = link.href().resolved(vocabulary.iri(url).unwrap());
|
|
|
|
|
context_url = Some(vocabulary.insert(u.as_iri()));
|
|
|
|
|
let iri_buf = link.href().resolved(
|
|
|
|
|
vocabulary
|
|
|
|
|
.iri(url)
|
|
|
|
|
.ok_or_else(|| Error::MalformedApub(String::from("Unresolved IRI")))?,
|
|
|
|
|
);
|
|
|
|
|
context_url = Some(vocabulary.insert(iri_buf.as_iri()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|