azure_core/policies/
transport.rs

1use crate::{
2    policies::{Policy, PolicyResult},
3    Context, Request, TransportOptions,
4};
5use async_trait::async_trait;
6use std::sync::Arc;
7use tracing::debug;
8
9#[derive(Debug, Clone)]
10pub struct TransportPolicy {
11    pub(crate) transport_options: TransportOptions,
12}
13
14impl TransportPolicy {
15    pub fn new(transport_options: TransportOptions) -> Self {
16        Self { transport_options }
17    }
18}
19
20#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
21#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
22impl Policy for TransportPolicy {
23    async fn send(
24        &self,
25        ctx: &Context,
26        request: &mut Request,
27        next: &[Arc<dyn Policy>],
28    ) -> PolicyResult {
29        // there must be no more policies
30        assert_eq!(0, next.len());
31
32        debug!("the following request will be passed to the transport policy: {request:#?}");
33        let response = { self.transport_options.send(ctx, request) };
34
35        response.await
36    }
37}