MCPcopy Create free account
hub / github.com/Firstyear/opensuse-proxy-cache / found

Function found

opensuse-proxy-cache/src/main.rs:1175–1281  ·  view source on GitHub ↗
(
    state: Arc<AppState>,
    obj: CacheObj<PathBuf, Status>,
    metadata: bool,
    range: Option<(u64, Option<u64>)>,
    client_ip_addr: IpAddr,
)

Source from the content-addressed store, hash-verified

1173
1174#[instrument(skip_all)]
1175async fn found(
1176 state: Arc<AppState>,
1177 obj: CacheObj<PathBuf, Status>,
1178 metadata: bool,
1179 range: Option<(u64, Option<u64>)>,
1180 client_ip_addr: IpAddr,
1181) -> Response {
1182 info!(
1183 "🔥 start found -> {:?} : range: {:?}",
1184 obj.fhandle.path, range
1185 );
1186
1187 let amt: u64 = obj.fhandle.amt as u64;
1188
1189 // rebuild headers.
1190 let mut headers = HeaderMap::new();
1191
1192 obj.userdata.headers.iter().for_each(|(k, v)| {
1193 headers.insert(
1194 HeaderName::from_str(k.as_str()).unwrap(),
1195 HeaderValue::from_str(v.as_str()).unwrap(),
1196 );
1197 });
1198
1199 let mut headers = filter_headers(&headers, metadata);
1200
1201 if metadata {
1202 return (StatusCode::OK, headers).into_response();
1203 }
1204
1205 // Not a head req - send the file!
1206 let mut n_file = match File::open(&obj.fhandle.path).await {
1207 Ok(f) => f,
1208 Err(e) => {
1209 error!("{:?}", e);
1210 return StatusCode::INTERNAL_SERVER_ERROR.into_response();
1211 }
1212 };
1213
1214 let (start, end) = match range {
1215 Some((start, None)) => {
1216 // If some clients already have the whole file, they'll send the byte range like this, so we
1217 // just ignore it and send the file again.
1218 if start == amt {
1219 (0, amt)
1220 } else {
1221 (start, amt)
1222 }
1223 }
1224 Some((start, Some(end))) => (start, end + 1),
1225 None => (0, amt),
1226 };
1227
1228 // Sanity check!
1229 if end <= start || end > amt {
1230 error!("Range failed {} <= {} || {} > {}", end, start, end, amt);
1231 return StatusCode::RANGE_NOT_SATISFIABLE.into_response();
1232 }

Callers 2

head_viewFunction · 0.85
get_viewFunction · 0.85

Calls 3

filter_headersFunction · 0.85
trace_client_req_sizeFunction · 0.85
insertMethod · 0.80

Tested by

no test coverage detected