(
headers: HeaderMap,
extract::Extension(client_ip_addr): extract::Extension<IpAddr>,
extract::State(state): extract::State<Arc<AppState>>,
extract::OriginalUri(req_uri): extract::Orig
| 197 | |
| 198 | #[instrument(skip_all)] |
| 199 | async 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, |
nothing calls this directly
no test coverage detected