If id of fetched object doesnt match url, refetch it (#126)

This commit is contained in:
Nutomic 2024-09-13 16:09:04 +02:00 committed by GitHub
parent 1126603b61
commit a35c8cbea5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -73,6 +73,14 @@ pub async fn fetch_object_http<T: Clone, Kind: DeserializeOwned>(
// Ensure id field matches final url after redirect // Ensure id field matches final url after redirect
if res.object_id.as_ref() != Some(&res.url) { if res.object_id.as_ref() != Some(&res.url) {
if let Some(res_object_id) = res.object_id {
// If id is different but still on the same domain, attempt to request object
// again from url in id field.
if res_object_id.domain() == res.url.domain() {
return Box::pin(fetch_object_http(&res_object_id, data)).await;
}
}
// Failed to fetch the object from its specified id
return Err(Error::FetchWrongId(res.url)); return Err(Error::FetchWrongId(res.url));
} }