(
port: u16,
asset_path: &str,
query: Option<&str>,
method: Method,
headers: HeaderMap,
body: Bytes,
)
| 1276 | } |
| 1277 | |
| 1278 | async fn metro_proxy_response( |
| 1279 | port: u16, |
| 1280 | asset_path: &str, |
| 1281 | query: Option<&str>, |
| 1282 | method: Method, |
| 1283 | headers: HeaderMap, |
| 1284 | body: Bytes, |
| 1285 | ) -> Response { |
| 1286 | let content_type = headers |
| 1287 | .get(header::CONTENT_TYPE) |
| 1288 | .and_then(|value| value.to_str().ok()); |
| 1289 | match devtools::fetch_metro_resource( |
| 1290 | port, |
| 1291 | asset_path, |
| 1292 | query, |
| 1293 | method.as_str(), |
| 1294 | Some(body.as_ref()), |
| 1295 | content_type, |
| 1296 | ) |
| 1297 | .await |
| 1298 | { |
| 1299 | Ok(asset) => { |
| 1300 | let status = StatusCode::from_u16(asset.status).unwrap_or(StatusCode::BAD_GATEWAY); |
| 1301 | let body = devtools::rewrite_metro_proxy_asset( |
| 1302 | port, |
| 1303 | asset_path, |
| 1304 | asset.content_type.as_deref(), |
| 1305 | asset.body, |
| 1306 | ); |
| 1307 | let mut builder = Response::builder() |
| 1308 | .status(status) |
| 1309 | .header(header::CACHE_CONTROL, "no-store"); |
| 1310 | if let Some(content_type) = asset.content_type { |
| 1311 | builder = builder.header(header::CONTENT_TYPE, content_type); |
| 1312 | } |
| 1313 | builder |
| 1314 | .body(Body::from(body)) |
| 1315 | .unwrap_or_else(|_| StatusCode::INTERNAL_SERVER_ERROR.into_response()) |
| 1316 | } |
| 1317 | Err(error) => { |
| 1318 | tracing::debug!("Metro proxy failed for {port}{asset_path}: {error}"); |
| 1319 | AppError::not_found("Metro resource is not available through the proxy.") |
| 1320 | .into_response() |
| 1321 | } |
| 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | async fn webkit_inspector_ui_file(method: Method, uri: Uri) -> Response { |
| 1326 | let Some(root) = webkit::webkit_inspector_ui_root() else { |
no test coverage detected