diff --git a/crates/web5/src/dids/methods/web/resolver.rs b/crates/web5/src/dids/methods/web/resolver.rs index 070c0f83..305e6b5e 100644 --- a/crates/web5/src/dids/methods/web/resolver.rs +++ b/crates/web5/src/dids/methods/web/resolver.rs @@ -39,46 +39,49 @@ impl Resolver { did_url: format!("https://{}/did.json", did_url), } } -} - -// This trait implements the actual logic for resolving a DID URI to a DID Document. -impl IntoFuture for Resolver { - type Output = Result; - type IntoFuture = Pin + Send + Sync>>; - fn into_future(self) -> Self::IntoFuture { + async fn resolve(url: String) -> Result { let mut headers = HeaderMap::new(); headers.append( reqwest::header::USER_AGENT, HeaderValue::from_static(USER_AGENT), ); - Box::pin(async move { - let client = reqwest::Client::builder() - .default_headers(headers) - .build() - .map_err(|_| ResolutionError::InternalError)?; + let client = reqwest::Client::builder() + .default_headers(headers) + .build() + .map_err(|_| ResolutionError::InternalError)?; - let response = client - .get(&self.did_url) - .send() + let response = client + .get(&url) + .send() + .await + .map_err(|_| ResolutionError::InternalError)?; + + if response.status().is_success() { + let did_document = response + .json::() .await - .map_err(|_| ResolutionError::InternalError)?; - - if response.status().is_success() { - let did_document = response - .json::() - .await - .map_err(|_| ResolutionError::RepresentationNotSupported)?; - - Ok(ResolutionResult { - did_document: Some(did_document), - ..Default::default() - }) - } else { - Err(ResolutionError::NotFound) - } - }) + .map_err(|_| ResolutionError::RepresentationNotSupported)?; + + Ok(ResolutionResult { + did_document: Some(did_document), + ..Default::default() + }) + } else { + Err(ResolutionError::NotFound) + } + } +} + +// This trait implements the actual logic for resolving a DID URI to a DID Document. +impl IntoFuture for Resolver { + type Output = Result; + type IntoFuture = Pin>>; + + fn into_future(self) -> Self::IntoFuture { + let did_url = self.did_url; + Box::pin(async move { Self::resolve(did_url).await }) } }