sentry/transports/
mod.rs

1//! The provided transports.
2//!
3//! This module exposes all transports that are compiled into the sentry
4//! library.  The `reqwest`, `curl`, `surf` and `ureq` features turn on these transports.
5
6use crate::{ClientOptions, Transport, TransportFactory};
7use std::sync::Arc;
8
9#[cfg(feature = "httpdate")]
10mod ratelimit;
11#[cfg(any(feature = "curl", feature = "ureq"))]
12mod thread;
13#[cfg(any(feature = "reqwest", feature = "surf",))]
14mod tokio_thread;
15
16#[cfg(feature = "reqwest")]
17mod reqwest;
18#[cfg(feature = "reqwest")]
19pub use self::reqwest::ReqwestHttpTransport;
20
21#[cfg(all(target_os = "espidf", feature = "embedded-svc-http"))]
22mod embedded_svc_http;
23#[cfg(all(target_os = "espidf", feature = "embedded-svc-http"))]
24pub use self::embedded_svc_http::EmbeddedSVCHttpTransport;
25
26#[cfg(feature = "curl")]
27mod curl;
28#[cfg(feature = "curl")]
29pub use self::curl::CurlHttpTransport;
30
31#[cfg(feature = "surf")]
32mod surf;
33#[cfg(feature = "surf")]
34pub use self::surf::SurfHttpTransport;
35
36#[cfg(feature = "ureq")]
37mod ureq;
38#[cfg(feature = "ureq")]
39pub use self::ureq::UreqHttpTransport;
40
41#[cfg(feature = "reqwest")]
42type DefaultTransport = ReqwestHttpTransport;
43
44#[cfg(all(
45    feature = "curl",
46    not(all(target_os = "espidf", feature = "embedded-svc-http")),
47    not(feature = "reqwest"),
48    not(feature = "surf"),
49    not(feature = "ureq")
50))]
51type DefaultTransport = CurlHttpTransport;
52
53#[cfg(all(
54    feature = "surf",
55    not(all(target_os = "espidf", feature = "embedded-svc-http")),
56    not(feature = "reqwest"),
57    not(feature = "curl"),
58    not(feature = "ureq")
59))]
60type DefaultTransport = SurfHttpTransport;
61
62#[cfg(all(
63    feature = "ureq",
64    not(all(target_os = "espidf", feature = "embedded-svc-http")),
65    not(feature = "reqwest"),
66    not(feature = "curl"),
67    not(feature = "surf")
68))]
69type DefaultTransport = UreqHttpTransport;
70
71#[cfg(all(
72    target_os = "espidf",
73    feature = "embedded-svc-http",
74    not(feature = "reqwest"),
75    not(feature = "curl"),
76    not(feature = "surf"),
77    not(feature = "ureq")
78))]
79type DefaultTransport = EmbeddedSVCHttpTransport;
80
81/// The default http transport.
82#[cfg(any(
83    all(target_os = "espidf", feature = "embedded-svc-http"),
84    feature = "reqwest",
85    feature = "curl",
86    feature = "surf",
87    feature = "ureq"
88))]
89pub type HttpTransport = DefaultTransport;
90
91/// Creates the default HTTP transport.
92///
93/// This is the default value for `transport` on the client options.  It
94/// creates a `HttpTransport`.  If no http transport was compiled into the
95/// library it will panic on transport creation.
96#[derive(Clone)]
97pub struct DefaultTransportFactory;
98
99impl TransportFactory for DefaultTransportFactory {
100    fn create_transport(&self, options: &ClientOptions) -> Arc<dyn Transport> {
101        #[cfg(any(
102            all(target_os = "espidf", feature = "embedded-svc-http"),
103            feature = "reqwest",
104            feature = "curl",
105            feature = "surf",
106            feature = "ureq"
107        ))]
108        {
109            Arc::new(HttpTransport::new(options))
110        }
111        #[cfg(not(any(
112            all(target_os = "espidf", feature = "embedded-svc-http"),
113            feature = "reqwest",
114            feature = "curl",
115            feature = "surf",
116            feature = "ureq"
117        )))]
118        {
119            let _ = options;
120            panic!("sentry crate was compiled without transport")
121        }
122    }
123}