MCPcopy Index your code
hub / github.com/Firstyear/opensuse-proxy-cache / refresh

Function refresh

opensuse-proxy-cache/src/main.rs:1284–1320  ·  view source on GitHub ↗
(client: &reqwest::Client, url: Url, obj: &CacheObj<PathBuf, Status>)

Source from the content-addressed store, hash-verified

1282
1283#[instrument(skip_all)]
1284async fn refresh(client: &reqwest::Client, url: Url, obj: &CacheObj<PathBuf, Status>) -> bool {
1285 info!("💸 start refresh ");
1286 // If we don't have an etag and/or last mod, treat as miss.
1287 // If we don't have a content-len we may have corrupt content,
1288 // so force the refresh.
1289
1290 // First do a head request.
1291 let send_headers = send_headers(None);
1292 let client_response = client.head(url).headers(send_headers).send().await;
1293
1294 let client_response = match client_response {
1295 Ok(cr) => cr,
1296 Err(e) => {
1297 error!(?e, "Error handling client response");
1298 // For now assume we can't proceed anyway
1299 return false;
1300 }
1301 };
1302
1303 let etag: Option<&str> = client_response
1304 .headers()
1305 .get("etag")
1306 .and_then(|hv| hv.to_str().ok());
1307
1308 let x_etag = obj.userdata.headers.get("etag");
1309
1310 debug!("etag -> {:?} == {:?}", etag, x_etag);
1311 if etag.is_some() && etag == x_etag.map(|s| s.as_str()) {
1312 // No need to refresh, continue.
1313 info!("💸 refresh not required");
1314 false
1315 } else {
1316 // No etag present from head request. Assume we need to refresh.
1317 info!("📉 refresh is required");
1318 true
1319 }
1320}
1321
1322async fn trace_client_req_size(
1323 daily_quota: Option<&Mutex<Quota>>,

Callers 2

get_viewFunction · 0.85
async_refresh_taskFunction · 0.85

Calls 2

send_headersFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected