Skip to content

Commit 6fb4473

Browse files
committed
Respect standard HTTP proxy environment variables
1 parent 6b82915 commit 6fb4473

11 files changed

Lines changed: 277 additions & 61 deletions

File tree

Cargo.lock

Lines changed: 69 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ rusqlite = { version = "0.31", features = ["bundled"] }
2222
libc = "0.2"
2323
jsonc-parser = { version = "0.32", features = ["cst"] }
2424
dirs = "5.0"
25-
ureq = { version = "2.12", default-features = false, features = ["native-tls"] }
26-
native-tls = "0.2"
25+
ureq = { version = "3.3", default-features = false, features = ["native-tls"] }
2726
url = "2.5"
2827
glob = "0.3"
2928
ignore = "0.4"

src/api/client.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,30 +188,39 @@ impl ApiContext {
188188
/// Create a GET request with common headers (User-Agent, X-Distinct-ID)
189189
/// Use this for all HTTP GET requests to ensure consistent headers.
190190
/// The returned (Agent, Request) pair uses the system's native certificate store.
191-
pub fn http_get(url: &str, timeout_secs: Option<u64>) -> (ureq::Agent, ureq::Request) {
191+
pub fn http_get(
192+
url: &str,
193+
timeout_secs: Option<u64>,
194+
) -> (
195+
ureq::Agent,
196+
ureq::RequestBuilder<ureq::typestate::WithoutBody>,
197+
) {
192198
let agent = http::build_agent(timeout_secs);
193199
let request = agent
194200
.get(url)
195-
.set(
201+
.header(
196202
"User-Agent",
197203
&format!("git-ai/{}", env!("CARGO_PKG_VERSION")),
198204
)
199-
.set("X-Distinct-ID", &config::get_or_create_distinct_id());
205+
.header("X-Distinct-ID", &config::get_or_create_distinct_id());
200206
(agent, request)
201207
}
202208

203209
/// Create a POST request with common headers (User-Agent, X-Distinct-ID)
204210
/// Use this for all HTTP POST requests to ensure consistent headers.
205211
/// The returned (Agent, Request) pair uses the system's native certificate store.
206-
pub fn http_post(url: &str, timeout_secs: Option<u64>) -> (ureq::Agent, ureq::Request) {
212+
pub fn http_post(
213+
url: &str,
214+
timeout_secs: Option<u64>,
215+
) -> (ureq::Agent, ureq::RequestBuilder<ureq::typestate::WithBody>) {
207216
let agent = http::build_agent(timeout_secs);
208217
let request = agent
209218
.post(url)
210-
.set(
219+
.header(
211220
"User-Agent",
212221
&format!("git-ai/{}", env!("CARGO_PKG_VERSION")),
213222
)
214-
.set("X-Distinct-ID", &config::get_or_create_distinct_id());
223+
.header("X-Distinct-ID", &config::get_or_create_distinct_id());
215224
(agent, request)
216225
}
217226

@@ -313,16 +322,16 @@ impl ApiContext {
313322
let body_json = serde_json::to_string(body).map_err(GitAiError::JsonError)?;
314323

315324
let (_agent, mut request) = Self::http_post(&url, self.timeout_secs);
316-
request = request.set("Content-Type", "application/json");
325+
request = request.header("Content-Type", "application/json");
317326

318327
if let Some(api_key) = &self.api_key {
319-
request = request.set("X-API-Key", api_key);
328+
request = request.header("X-API-Key", api_key);
320329
if let Some(identity) = &self.author_identity {
321-
request = request.set("X-Author-Identity", identity);
330+
request = request.header("X-Author-Identity", identity);
322331
}
323332
}
324333
if let Some(token) = &self.auth_token {
325-
request = request.set("Authorization", &format!("Bearer {}", token));
334+
request = request.header("Authorization", &format!("Bearer {}", token));
326335
}
327336

328337
http::send_with_body(request, &body_json)
@@ -336,13 +345,13 @@ impl ApiContext {
336345
let (_agent, mut request) = Self::http_get(&url, self.timeout_secs);
337346

338347
if let Some(api_key) = &self.api_key {
339-
request = request.set("X-API-Key", api_key);
348+
request = request.header("X-API-Key", api_key);
340349
if let Some(identity) = &self.author_identity {
341-
request = request.set("X-Author-Identity", identity);
350+
request = request.header("X-Author-Identity", identity);
342351
}
343352
}
344353
if let Some(token) = &self.auth_token {
345-
request = request.set("Authorization", &format!("Bearer {}", token));
354+
request = request.header("Authorization", &format!("Bearer {}", token));
346355
}
347356

348357
http::send(request).map_err(|e| GitAiError::Generic(format!("HTTP request failed: {}", e)))

src/auth/client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl OAuthClient {
6060
let url = format!("{}/worker/oauth/token", self.base_url);
6161

6262
let (_agent, request) = ApiContext::http_post(&url, Some(30));
63-
let request = request.set("Content-Type", "application/json");
63+
let request = request.header("Content-Type", "application/json");
6464
let response = http::send_with_body(request, &body.to_string())
6565
.map_err(|e| format!("Failed to connect to server: {}", e))?;
6666

@@ -98,7 +98,7 @@ impl OAuthClient {
9898
let url = format!("{}/worker/oauth/device/code", self.base_url);
9999

100100
let (_agent, request) = ApiContext::http_post(&url, Some(30));
101-
let request = request.set("Content-Type", "application/json");
101+
let request = request.header("Content-Type", "application/json");
102102
let response = http::send_with_body(request, "{}")
103103
.map_err(|e| format!("Failed to connect to server: {}", e))?;
104104

@@ -142,7 +142,7 @@ impl OAuthClient {
142142
});
143143

144144
let (_agent, request) = ApiContext::http_post(&url, Some(30));
145-
let request = request.set("Content-Type", "application/json");
145+
let request = request.header("Content-Type", "application/json");
146146
let response = http::send_with_body(request, &body.to_string())
147147
.map_err(|e| format!("Failed to connect to server: {}", e))?;
148148

src/ci/gitlab.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,13 @@ fn gitlab_api_get(
8585
auth_token: &str,
8686
) -> Result<crate::http::Response, String> {
8787
let agent = crate::http::build_agent(Some(30));
88-
let request = agent.get(endpoint).set(auth_header_name, auth_token).set(
89-
"User-Agent",
90-
&format!("git-ai/{}", env!("CARGO_PKG_VERSION")),
91-
);
88+
let request = agent
89+
.get(endpoint)
90+
.header(auth_header_name, auth_token)
91+
.header(
92+
"User-Agent",
93+
&format!("git-ai/{}", env!("CARGO_PKG_VERSION")),
94+
);
9295
crate::http::send(request)
9396
}
9497

@@ -300,8 +303,8 @@ pub fn get_gitlab_ci_context() -> Result<Option<CiContext>, GitAiError> {
300303
let agent = crate::http::build_agent(Some(30));
301304
let request = agent
302305
.get(&source_project_endpoint)
303-
.set(auth_header_name, &auth_token)
304-
.set(
306+
.header(auth_header_name, &auth_token)
307+
.header(
305308
"User-Agent",
306309
&format!("git-ai/{}", env!("CARGO_PKG_VERSION")),
307310
);

src/commands/analyze/cube.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ impl CubeClient {
8787
let request = self
8888
.agent
8989
.post(&self.url(path))
90-
.set("x-api-key", &self.api_key)
91-
.set("Content-Type", "application/json");
90+
.header("x-api-key", &self.api_key)
91+
.header("Content-Type", "application/json");
9292
let body_str = serde_json::to_string(body).map_err(|e| CubeError::Json(e.to_string()))?;
9393
let response = http::send_with_body(request, &body_str).map_err(CubeError::Transport)?;
9494
Self::parse(response)
@@ -99,7 +99,7 @@ impl CubeClient {
9999
let request = self
100100
.agent
101101
.get(&self.url(path))
102-
.set("x-api-key", &self.api_key);
102+
.header("x-api-key", &self.api_key);
103103
let response = http::send(request).map_err(CubeError::Transport)?;
104104
Self::parse(response)
105105
}

src/daemon/telemetry_worker.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ fn flush_sentry_and_posthog(
12471247
let agent = crate::http::build_agent(Some(30));
12481248
let request = agent
12491249
.post(&endpoint)
1250-
.set("Content-Type", "application/json");
1250+
.header("Content-Type", "application/json");
12511251
let _ = crate::http::send_with_body(
12521252
request,
12531253
&serde_json::to_string(&ph_event).unwrap_or_default(),
@@ -1499,8 +1499,8 @@ impl SentryClient {
14991499
let agent = crate::http::build_agent(Some(30));
15001500
let request = agent
15011501
.post(&self.endpoint)
1502-
.set("X-Sentry-Auth", &auth_header)
1503-
.set("Content-Type", "application/json");
1502+
.header("X-Sentry-Auth", &auth_header)
1503+
.header("Content-Type", "application/json");
15041504
let response = crate::http::send_with_body(request, &body)?;
15051505

15061506
let status = response.status_code;

0 commit comments

Comments
 (0)