nightly url setting (#7037)
Release Notes: - Added the ability to set settings per-release stage - Added a `"server_url"` setting
This commit is contained in:
parent
c07355265f
commit
dfbcaf36fc
12 changed files with 217 additions and 76 deletions
|
@ -30,6 +30,7 @@ serde_json.workspace = true
|
|||
git2 = { workspace = true, optional = true }
|
||||
dirs = "3.0"
|
||||
take-until = "0.2.0"
|
||||
parking_lot.workspace = true
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
tendril = "0.4.3"
|
||||
|
|
|
@ -6,12 +6,49 @@ pub use isahc::{
|
|||
Error,
|
||||
};
|
||||
pub use isahc::{AsyncBody, Request, Response};
|
||||
use parking_lot::Mutex;
|
||||
use smol::future::FutureExt;
|
||||
#[cfg(feature = "test-support")]
|
||||
use std::fmt;
|
||||
use std::{sync::Arc, time::Duration};
|
||||
pub use url::Url;
|
||||
|
||||
pub struct ZedHttpClient {
|
||||
pub zed_host: Mutex<String>,
|
||||
client: Box<dyn HttpClient>,
|
||||
}
|
||||
|
||||
impl ZedHttpClient {
|
||||
pub fn zed_url(&self, path: &str) -> String {
|
||||
format!("{}{}", self.zed_host.lock(), path)
|
||||
}
|
||||
}
|
||||
|
||||
impl HttpClient for Arc<ZedHttpClient> {
|
||||
fn send(&self, req: Request<AsyncBody>) -> BoxFuture<Result<Response<AsyncBody>, Error>> {
|
||||
self.client.send(req)
|
||||
}
|
||||
}
|
||||
|
||||
impl HttpClient for ZedHttpClient {
|
||||
fn send(&self, req: Request<AsyncBody>) -> BoxFuture<Result<Response<AsyncBody>, Error>> {
|
||||
self.client.send(req)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn zed_client(zed_host: &str) -> Arc<ZedHttpClient> {
|
||||
Arc::new(ZedHttpClient {
|
||||
zed_host: Mutex::new(zed_host.to_string()),
|
||||
client: Box::new(
|
||||
isahc::HttpClient::builder()
|
||||
.connect_timeout(Duration::from_secs(5))
|
||||
.low_speed_timeout(100, Duration::from_secs(5))
|
||||
.build()
|
||||
.unwrap(),
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
pub trait HttpClient: Send + Sync {
|
||||
fn send(&self, req: Request<AsyncBody>) -> BoxFuture<Result<Response<AsyncBody>, Error>>;
|
||||
|
||||
|
@ -81,17 +118,20 @@ pub struct FakeHttpClient {
|
|||
|
||||
#[cfg(feature = "test-support")]
|
||||
impl FakeHttpClient {
|
||||
pub fn create<Fut, F>(handler: F) -> Arc<dyn HttpClient>
|
||||
pub fn create<Fut, F>(handler: F) -> Arc<ZedHttpClient>
|
||||
where
|
||||
Fut: 'static + Send + futures::Future<Output = Result<Response<AsyncBody>, Error>>,
|
||||
F: 'static + Send + Sync + Fn(Request<AsyncBody>) -> Fut,
|
||||
{
|
||||
Arc::new(Self {
|
||||
handler: Box::new(move |req| Box::pin(handler(req))),
|
||||
Arc::new(ZedHttpClient {
|
||||
zed_host: Mutex::new("http://test.example".into()),
|
||||
client: Box::new(Self {
|
||||
handler: Box::new(move |req| Box::pin(handler(req))),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn with_404_response() -> Arc<dyn HttpClient> {
|
||||
pub fn with_404_response() -> Arc<ZedHttpClient> {
|
||||
Self::create(|_| async move {
|
||||
Ok(Response::builder()
|
||||
.status(404)
|
||||
|
@ -100,7 +140,7 @@ impl FakeHttpClient {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn with_200_response() -> Arc<dyn HttpClient> {
|
||||
pub fn with_200_response() -> Arc<ZedHttpClient> {
|
||||
Self::create(|_| async move {
|
||||
Ok(Response::builder()
|
||||
.status(200)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue