awc: new fetch api

This commit is contained in:
Aode (lion) 2021-11-22 16:50:08 -06:00
parent e7a34dd33b
commit 1718b90083

View file

@ -100,11 +100,11 @@ where
async fn do_fetch<Id: Dereference>( async fn do_fetch<Id: Dereference>(
&self, &self,
id: &Id, url: &Url,
) -> Result<Option<<Id as Dereference>::Output>, AwcError<SignError<Crypto>>> { ) -> Result<Option<<Id as Dereference>::Output>, AwcError<SignError<Crypto>>> {
let mut response = self let mut response = self
.client .client
.get(id.url().as_str()) .get(url.as_str())
.insert_header(("Accept", "application/activity+json")) .insert_header(("Accept", "application/activity+json"))
.insert_header(("Date", HttpDate::from(SystemTime::now()))) .insert_header(("Date", HttpDate::from(SystemTime::now())))
.signature(self.config.clone(), self.crypto.key_id(), { .signature(self.config.clone(), self.crypto.key_id(), {
@ -132,12 +132,10 @@ where
Box<dyn Future<Output = Result<Option<<Id as Dereference>::Output>, Self::Error>> + 'a>, Box<dyn Future<Output = Result<Option<<Id as Dereference>::Output>, Self::Error>> + 'a>,
>; >;
fn fetch(&'a self, id: &'a Id) -> Self::Future { fn fetch(&'a self, id: Id) -> Self::Future {
Box::pin(apub_core::session::guard( Box::pin(async move {
self.do_fetch(id), apub_core::session::guard(self.do_fetch::<Id>(id.url()), id.url(), &self.session).await
id.url(), })
&self.session,
))
} }
} }