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

Function head_view

opensuse-proxy-cache/src/main.rs:131–194  ·  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

129
130#[instrument(skip_all)]
131async fn head_view(
132 headers: HeaderMap,
133 extract::Extension(client_ip_addr): extract::Extension<IpAddr>,
134 extract::State(state): extract::State<Arc<AppState>>,
135 extract::OriginalUri(req_uri): extract::OriginalUri,
136) -> Response {
137 // let req_path = req_uri.path();
138 // let req_path = format!("/{}", req_path.replace("//", "/"));
139
140 let req_path = normalise_path(req_uri.path());
141
142 trace!("{:?}", req_path);
143 info!("request_headers -> {:?}", headers);
144
145 let decision = state.cache.decision(&req_path, true);
146 // Based on the decision, take an appropriate path. Generally with head reqs
147 // we try to stream this if we don't have it, and we prefetch in the BG.
148 match decision {
149 CacheDecision::Stream(url) => stream(state, url, true, None, client_ip_addr).await,
150 CacheDecision::NotFound => missing().await,
151 CacheDecision::FoundObj(meta) => found(state, meta, true, None, client_ip_addr).await,
152 CacheDecision::Refresh {
153 fetch_url,
154 submit_tx,
155 prefetch_items,
156 ..
157 }
158 | CacheDecision::MissObj {
159 fetch_url,
160 submit_tx,
161 prefetch_items,
162 ..
163 } => {
164 // Submit all our BG prefetch reqs
165 prefetch(state.prefetch_tx.clone(), &submit_tx, prefetch_items);
166 // Now we just stream.
167 stream(state, fetch_url, true, None, client_ip_addr).await
168 }
169 CacheDecision::AsyncRefresh {
170 fetch_url,
171 _cache_key: _,
172 tmp_file,
173 submit_tx,
174 meta,
175 prefetch_items,
176 } => {
177 // Submit all our BG prefetch reqs
178 async_refresh(
179 state.client.clone(),
180 state.prefetch_tx.clone(),
181 &fetch_url,
182 &submit_tx,
183 tmp_file,
184 &meta,
185 prefetch_items,
186 );
187 // Send our current head data.
188 found(state, meta, true, None, client_ip_addr).await

Callers

nothing calls this directly

Calls 8

normalise_pathFunction · 0.85
streamFunction · 0.85
missingFunction · 0.85
foundFunction · 0.85
prefetchFunction · 0.85
async_refreshFunction · 0.85
pathMethod · 0.80
decisionMethod · 0.80

Tested by

no test coverage detected