|
5 | 5 |
|
6 | 6 | use super::{schema::AgentInfo, AGENT_INFO_CACHE}; |
7 | 7 | use anyhow::{anyhow, Result}; |
8 | | -use http_body_util::BodyExt; |
9 | | -use hyper::{self, header::HeaderName}; |
10 | | -use libdd_common::{hyper_migration, worker::Worker, Endpoint}; |
| 8 | +use hyper::header::HeaderName; |
| 9 | +use libdd_common::{entity_id, worker::Worker, Endpoint}; |
| 10 | +use libdd_provider::{DefaultHttpClient, HttpClientTrait, HttpRequest}; |
11 | 11 | use sha2::{Digest, Sha256}; |
12 | 12 | use std::sync::Arc; |
13 | 13 | use std::time::Duration; |
@@ -81,15 +81,25 @@ pub async fn fetch_info(info_endpoint: &Endpoint) -> Result<Box<AgentInfo>> { |
81 | 81 | /// Returns a tuple of (state_hash, response_body_bytes). |
82 | 82 | /// The hash is calculated using SHA256 to match the agent's calculation method. |
83 | 83 | async fn fetch_and_hash_response(info_endpoint: &Endpoint) -> Result<(String, bytes::Bytes)> { |
84 | | - let req = info_endpoint |
85 | | - .to_request_builder(concat!("Libdatadog/", env!("CARGO_PKG_VERSION")))? |
86 | | - .method(hyper::Method::GET) |
87 | | - .body(hyper_migration::Body::empty()); |
88 | | - let client = hyper_migration::new_default_client(); |
89 | | - let res = client.request(req?).await?; |
90 | | - |
91 | | - let body_bytes = res.into_body().collect().await?; |
92 | | - let body_data = body_bytes.to_bytes(); |
| 84 | + let user_agent = concat!("Libdatadog/", env!("CARGO_PKG_VERSION")); |
| 85 | + let mut req = |
| 86 | + HttpRequest::get(info_endpoint.url.to_string()).with_header("user-agent", user_agent); |
| 87 | + |
| 88 | + // Add optional endpoint headers (api-key, test-token) |
| 89 | + for (name, value) in info_endpoint.get_optional_headers() { |
| 90 | + req = req.with_header(name, value); |
| 91 | + } |
| 92 | + |
| 93 | + // Add entity-related headers (container-id, entity-id, external-env) |
| 94 | + for (name, value) in entity_id::get_entity_headers() { |
| 95 | + req = req.with_header(name, value); |
| 96 | + } |
| 97 | + |
| 98 | + let res = DefaultHttpClient::request(req) |
| 99 | + .await |
| 100 | + .map_err(|e| anyhow!("{}", e))?; |
| 101 | + |
| 102 | + let body_data = bytes::Bytes::from(res.body); |
93 | 103 | let hash = format!("{:x}", Sha256::digest(&body_data)); |
94 | 104 |
|
95 | 105 | Ok((hash, body_data)) |
|
0 commit comments