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

Method decision

opensuse-proxy-cache/src/cache.rs:283–501  ·  view source on GitHub ↗
(&self, req_path: &Path, head_req: bool)

Source from the content-addressed store, hash-verified

281 }
282
283 pub fn decision(&self, req_path: &Path, head_req: bool) -> CacheDecision {
284 // let req_path_trim = req_path.replace("//", "/");
285 let req_path_trim = req_path;
286
287 info!("🤔 contemplating req -> {}", req_path_trim.display());
288
289 // If the path fails some validations, refuse to proceed.
290 if req_path_trim.is_relative() {
291 error!("path not absolute");
292 return CacheDecision::Invalid;
293 }
294
295 let fname = if req_path_trim.ends_with("/") {
296 "index.html".to_string()
297 } else {
298 req_path_trim
299 .file_name()
300 .and_then(|f| f.to_str().map(str::to_string))
301 .unwrap_or_else(|| "index.html".to_string())
302 };
303
304 debug!(" fname --> {:?}", fname);
305
306 // This is where we now need to make choices about the prefix on the
307 // req path.
308 //
309 // We need to see if a prefix matches?
310 //
311 // If it does, pull that backend. We then need to change the path from req_path
312 // to rel_path.
313
314 let context = self
315 .backends
316 .iter()
317 .find(|backend| req_path.starts_with(&backend.prefix))
318 .unwrap_or(&self.default_backend);
319
320 let Ok(relative_path) = req_path_trim.strip_prefix(&context.prefix) else {
321 error!("Unable to strip prefix, this is really weird...");
322 return CacheDecision::NotFound;
323 };
324
325 let cache_key = req_path_trim.to_path_buf();
326
327 info!(selected_context = ?context.prefix, ?relative_path);
328
329 /*
330 if relative_path.is_relative() {
331
332 }
333 */
334
335 let upstream_online = context.online.load(Ordering::Relaxed);
336
337 let cls = self.classify(&fname, &relative_path);
338
339 // Just go away.
340 if cls == Classification::Spam {

Callers 2

head_viewFunction · 0.80
get_viewFunction · 0.80

Calls 5

classifyMethod · 0.80
new_tempfileMethod · 0.80
urlMethod · 0.80
prefetchMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected