(
state: Arc<AppState>,
fetch_url: Url,
cache_key: PathBuf,
tmp_file: NamedTempFile,
submit_tx: Sender<CacheMeta>,
cls: Classification,
range: Option<(u64, Option<u64>)>,
| 527 | |
| 528 | #[instrument(skip_all)] |
| 529 | async fn miss( |
| 530 | state: Arc<AppState>, |
| 531 | fetch_url: Url, |
| 532 | cache_key: PathBuf, |
| 533 | tmp_file: NamedTempFile, |
| 534 | submit_tx: Sender<CacheMeta>, |
| 535 | cls: Classification, |
| 536 | range: Option<(u64, Option<u64>)>, |
| 537 | client_ip_addr: IpAddr, |
| 538 | ) -> Response { |
| 539 | info!("❄️ start miss "); |
| 540 | debug!("range -> {:?}", range); |
| 541 | |
| 542 | if range.is_some() { |
| 543 | info!("Range request, submitting bg dl with rangestream"); |
| 544 | |
| 545 | if state |
| 546 | .prefetch_tx |
| 547 | .send(PrefetchReq { |
| 548 | cache_key, |
| 549 | fetch_url: fetch_url.clone(), |
| 550 | submit_tx, |
| 551 | tmp_file, |
| 552 | cls, |
| 553 | }) |
| 554 | .await |
| 555 | .is_err() |
| 556 | { |
| 557 | error!("Prefetch task may have died!"); |
| 558 | } |
| 559 | |
| 560 | // Stream. metadata=false because we want the body. |
| 561 | return stream(state, fetch_url, false, range, client_ip_addr).await; |
| 562 | } |
| 563 | |
| 564 | // Not a range, go on. |
| 565 | info!("Not a range request, as you were."); |
| 566 | |
| 567 | // Start the dl. |
| 568 | let send_headers = send_headers(None); |
| 569 | let client_response = state |
| 570 | .client |
| 571 | .get(fetch_url) |
| 572 | .headers(send_headers) |
| 573 | .send() |
| 574 | .await; |
| 575 | |
| 576 | let client_response = match client_response { |
| 577 | Ok(cr) => cr, |
| 578 | Err(e) => { |
| 579 | error!(?e, "Error handling client response"); |
| 580 | return (StatusCode::INTERNAL_SERVER_ERROR).into_response(); |
| 581 | } |
| 582 | }; |
| 583 | |
| 584 | let headers = filter_headers(client_response.headers(), false); |
| 585 | |
| 586 | // Since it's not a range request, the content-length is the full file size we are about |
no test coverage detected