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

Function get_view

opensuse-proxy-cache/src/main.rs:199–344  ·  view source on GitHub ↗
(
    headers: HeaderMap,
    extract::Extension(client_ip_addr): extract::Extension<IpAddr>,
    extract::State(state): extract::State<Arc<AppState>>,
    extract::OriginalUri(req_uri): extract::Orig

Source from the content-addressed store, hash-verified

197
198#[instrument(skip_all)]
199async fn get_view(
200 headers: HeaderMap,
201 extract::Extension(client_ip_addr): extract::Extension<IpAddr>,
202 extract::State(state): extract::State<Arc<AppState>>,
203 extract::OriginalUri(req_uri): extract::OriginalUri,
204) -> Response {
205 // let req_path = req_uri.path();
206
207 let req_path = normalise_path(req_uri.path());
208
209 trace!("{:?}", req_path);
210 info!("request_headers -> {:?}", headers);
211
212 let decision = state.cache.decision(&req_path, false);
213 // Req path sometimes has dup //, so we replace them.
214
215 // We have a hit, with our cache meta! Hooray!
216 // Let's setup the response, and then stream from the file!
217 let range = headers
218 .get("range")
219 .and_then(|hv| hv.to_str().ok())
220 .and_then(|sr| {
221 if sr.starts_with("bytes=") {
222 sr.strip_prefix("bytes=")
223 .and_then(|v| v.split_once('-'))
224 .and_then(|(range_start, range_end)| {
225 let r_end = u64::from_str_radix(range_end, 10).ok();
226 u64::from_str_radix(range_start, 10)
227 .ok()
228 .map(|s| (s, r_end))
229 })
230 } else {
231 None
232 }
233 });
234
235 // Based on the decision, take an appropriate path.
236 match decision {
237 CacheDecision::Stream(url) => stream(state, url, false, range, client_ip_addr).await,
238 CacheDecision::NotFound => missing().await,
239 CacheDecision::FoundObj(meta) => found(state, meta, false, range, client_ip_addr).await,
240 CacheDecision::MissObj {
241 fetch_url,
242 cache_key,
243 tmp_file,
244 submit_tx,
245 cls,
246 prefetch_items,
247 } => {
248 // Submit all our BG prefetch reqs
249 prefetch(state.prefetch_tx.clone(), &submit_tx, prefetch_items);
250
251 miss(
252 state,
253 fetch_url,
254 cache_key,
255 tmp_file,
256 submit_tx,

Callers

nothing calls this directly

Calls 11

normalise_pathFunction · 0.85
streamFunction · 0.85
missingFunction · 0.85
foundFunction · 0.85
prefetchFunction · 0.85
missFunction · 0.85
refreshFunction · 0.85
async_refreshFunction · 0.85
pathMethod · 0.80
decisionMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected