Enable connection timeouts for requests
ci/woodpecker/push/ociImagePush Pipeline was successful
Details
ci/woodpecker/push/ociImagePush Pipeline was successful
Details
Hopefully reducing congestion
This commit is contained in:
parent
dab7585a8b
commit
277dcb5e3e
|
@ -4,6 +4,7 @@ use headers::UserAgent;
|
|||
use hyper::body::Bytes;
|
||||
use reqwest::{redirect::Policy, Client, RequestBuilder};
|
||||
use serde_json::Value;
|
||||
use std::time::Duration;
|
||||
use thiserror::Error;
|
||||
use tokio::pin;
|
||||
use url::Url;
|
||||
|
@ -58,6 +59,7 @@ impl FederationClient {
|
|||
let client = Client::builder()
|
||||
.https_only(force_https)
|
||||
.redirect(Policy::limited(5))
|
||||
.connect_timeout(Duration::from_secs(timeout_seconds))
|
||||
.build()?;
|
||||
|
||||
Ok(FederationClient {
|
||||
|
@ -119,7 +121,7 @@ impl FederationRequestBuilder<'_> {
|
|||
|
||||
async fn send_stream(
|
||||
self,
|
||||
) -> Result<impl Stream<Item = Result<Bytes, FederationClientError>>, FederationClientError>
|
||||
) -> Result<impl Stream<Item=Result<Bytes, FederationClientError>>, FederationClientError>
|
||||
{
|
||||
let mut body = self
|
||||
.builder
|
||||
|
@ -147,7 +149,7 @@ impl FederationRequestBuilder<'_> {
|
|||
let sleep = tokio::time::sleep(tokio::time::Duration::from_secs(
|
||||
self.client.timeout_seconds,
|
||||
))
|
||||
.fuse();
|
||||
.fuse();
|
||||
tokio::pin!(sleep);
|
||||
|
||||
let body = async move {
|
||||
|
@ -159,7 +161,7 @@ impl FederationRequestBuilder<'_> {
|
|||
})
|
||||
.await
|
||||
}
|
||||
.fuse();
|
||||
.fuse();
|
||||
|
||||
pin!(body);
|
||||
|
||||
|
|
|
@ -15,18 +15,18 @@ pub(super) fn new_federation_client_service(
|
|||
FederationClient::new(
|
||||
true,
|
||||
256000,
|
||||
35,
|
||||
25,
|
||||
UserAgent::from_str(&format!(
|
||||
"magnetar/{} (https://{})",
|
||||
config.branding.version, config.networking.host
|
||||
))
|
||||
.into_diagnostic()?,
|
||||
.into_diagnostic()?,
|
||||
)
|
||||
.into_diagnostic()
|
||||
.into_diagnostic()
|
||||
}
|
||||
|
||||
pub(super) fn new_ap_client_service(
|
||||
federation_client: impl AsRef<FederationClient> + Send + Sync + 'static,
|
||||
) -> impl ApClientService<Error = ApClientError> {
|
||||
) -> impl ApClientService<Error=ApClientError> {
|
||||
ApClientServiceDefaultProvider::new(federation_client)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue