Skip to content

Commit

Permalink
Merge branch 'sreeise:master' into merge-back
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeadie authored Sep 9, 2024
2 parents 1d10b56 + 8636b35 commit bf2e1c4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
53 changes: 27 additions & 26 deletions graph-http/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,33 @@ impl GraphClientConfiguration {
self
}

pub(crate) fn build_tower_service(
&self,
client: &reqwest::Client,
) -> BoxCloneService<Request, Response, Box<dyn std::error::Error + Send + Sync>> {
tower::ServiceBuilder::new()
.option_layer(
self.config
.service_layers_configuration
.retry
.map(|num| RetryLayer::new(crate::tower_services::Attempts(num))),
)
.option_layer(
self.config
.service_layers_configuration
.wait_for_retry_after_headers
.map(|_| RetryLayer::new(crate::tower_services::WaitFor())),
)
.option_layer(
self.config
.service_layers_configuration
.concurrency_limit
.map(ConcurrencyLimitLayer::new),
)
.service(client.clone())
.boxed_clone()
}

pub fn build(self) -> Client {
let config = self.clone();
let headers = self.config.headers.clone();
Expand All @@ -252,43 +279,19 @@ impl GraphClientConfiguration {

let client = builder.build().unwrap();

let service = tower::ServiceBuilder::new()
.option_layer(
self.config
.service_layers_configuration
.retry
.map(|num| RetryLayer::new(crate::tower_services::Attempts(num))),
)
.option_layer(
self.config
.service_layers_configuration
.wait_for_retry_after_headers
.map(|_| RetryLayer::new(crate::tower_services::WaitFor())),
)
.option_layer(
self.config
.service_layers_configuration
.concurrency_limit
.map(ConcurrencyLimitLayer::new),
)
.service(client.clone())
.boxed_clone();

if let Some(client_application) = self.config.client_application {
Client {
client_application,
inner: client,
headers,
builder: config,
service,
}
} else {
Client {
client_application: Box::<String>::default(),
inner: client,
headers,
builder: config,
service,
}
}
}
Expand Down Expand Up @@ -345,8 +348,6 @@ pub struct Client {
pub(crate) inner: reqwest::Client,
pub(crate) headers: HeaderMap,
pub(crate) builder: GraphClientConfiguration,
pub(crate) service:
BoxCloneService<Request, Response, Box<dyn std::error::Error + Send + Sync>>,
}

impl Client {
Expand Down
2 changes: 1 addition & 1 deletion graph-http/src/request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl RequestHandler {
err: Option<GraphFailure>,
body: Option<BodyRead>,
) -> RequestHandler {
let service = inner.service.clone();
let service = inner.builder.build_tower_service(&inner.inner);
let client_builder = inner.builder.clone();
let mut original_headers = inner.headers.clone();
original_headers.extend(request_components.headers.clone());
Expand Down

0 comments on commit bf2e1c4

Please sign in to comment.