http_client: Relax lifetime bounds and add fluent builder methods (#38448)

`HttpClient`: Relaxes the lifetime bound to `&self` in `get`/`post`
by returning the `self.send` future directly. This makes both
methods return `'static` futures without extra boxing.

`HttpRequestExt`: Added fluent builder methods to `HttpRequestExt`
inspired by the `gpui::FluentBuilder` trait.

Release Notes:

- N/A
This commit is contained in:
tidely
2025-09-19 01:39:26 +02:00
committed by GitHub
parent b09764c54a
commit f18b19a73e
5 changed files with 72 additions and 61 deletions
+11 -10
View File
@@ -9,7 +9,7 @@ use futures::AsyncReadExt as _;
use gpui::{App, Task};
use gpui_tokio::Tokio;
use http_client::http::request;
use http_client::{AsyncBody, HttpClientWithUrl, Method, Request, StatusCode};
use http_client::{AsyncBody, HttpClientWithUrl, HttpRequestExt, Method, Request, StatusCode};
use parking_lot::RwLock;
use yawc::WebSocket;
@@ -119,15 +119,16 @@ impl CloudApiClient {
&self,
system_id: Option<String>,
) -> Result<CreateLlmTokenResponse> {
let mut request_builder = Request::builder().method(Method::POST).uri(
self.http_client
.build_zed_cloud_url("/client/llm_tokens", &[])?
.as_ref(),
);
if let Some(system_id) = system_id {
request_builder = request_builder.header(ZED_SYSTEM_ID_HEADER_NAME, system_id);
}
let request_builder = Request::builder()
.method(Method::POST)
.uri(
self.http_client
.build_zed_cloud_url("/client/llm_tokens", &[])?
.as_ref(),
)
.when_some(system_id, |builder, system_id| {
builder.header(ZED_SYSTEM_ID_HEADER_NAME, system_id)
});
let request = self.build_request(request_builder, AsyncBody::default())?;