(server: &str, tls: &TlsOptions)
| 1404 | } |
| 1405 | |
| 1406 | async fn http_health_check(server: &str, tls: &TlsOptions) -> Result<Option<StatusCode>> { |
| 1407 | let base = server.trim_end_matches('/'); |
| 1408 | let uri: hyper::Uri = format!("{base}/healthz").parse().into_diagnostic()?; |
| 1409 | |
| 1410 | let scheme = uri.scheme_str().unwrap_or("https"); |
| 1411 | let https = if tls.gateway_insecure && scheme.eq_ignore_ascii_case("https") { |
| 1412 | let insecure_config = build_insecure_rustls_config()?; |
| 1413 | HttpsConnectorBuilder::new() |
| 1414 | .with_tls_config(insecure_config) |
| 1415 | .https_or_http() |
| 1416 | .enable_http1() |
| 1417 | .build() |
| 1418 | } else if scheme.eq_ignore_ascii_case("http") || tls.is_bearer_auth() { |
| 1419 | HttpsConnectorBuilder::new() |
| 1420 | .with_native_roots() |
| 1421 | .into_diagnostic()? |
| 1422 | .https_or_http() |
| 1423 | .enable_http1() |
| 1424 | .build() |
| 1425 | } else { |
| 1426 | let materials = require_tls_materials(server, tls)?; |
| 1427 | let tls_config = build_rustls_config(&materials)?; |
| 1428 | HttpsConnectorBuilder::new() |
| 1429 | .with_tls_config(tls_config) |
| 1430 | .https_only() |
| 1431 | .enable_http1() |
| 1432 | .build() |
| 1433 | }; |
| 1434 | let client: Client<_, Full<Bytes>> = Client::builder(TokioExecutor::new()).build(https); |
| 1435 | let mut req_builder = Request::builder().method("GET").uri(uri); |
| 1436 | // Inject edge authentication headers when an edge token is configured. |
| 1437 | if let Some(ref token) = tls.edge_token { |
| 1438 | req_builder = req_builder |
| 1439 | .header("Cf-Access-Jwt-Assertion", token.as_str()) |
| 1440 | .header("Cookie", format!("CF_Authorization={token}")); |
| 1441 | } |
| 1442 | let req = req_builder |
| 1443 | .body(Full::new(Bytes::new())) |
| 1444 | .into_diagnostic()?; |
| 1445 | let resp = client.request(req).await.into_diagnostic()?; |
| 1446 | Ok(Some(resp.status())) |
| 1447 | } |
| 1448 | |
| 1449 | async fn gateway_reachable(server: &str, tls: &TlsOptions) -> bool { |
| 1450 | if let Ok(mut client) = grpc_client(server, tls).await |
no test coverage detected