1 //! The provided transports.
2 //!
3 //! This module exposes all transports that are compiled into the sentry
4 //! library.  The `reqwest`, `curl` and `surf` features turn on these transports.
5 
6 use crate::{ClientOptions, Transport, TransportFactory};
7 use std::sync::Arc;
8 
9 #[cfg(any(feature = "reqwest", feature = "curl", feature = "surf"))]
10 mod ratelimit;
11 #[cfg(any(feature = "reqwest", feature = "curl", feature = "surf"))]
12 mod thread;
13 
14 #[cfg(feature = "reqwest")]
15 mod reqwest;
16 #[cfg(feature = "reqwest")]
17 pub use reqwest::ReqwestHttpTransport;
18 
19 #[cfg(feature = "curl")]
20 mod curl;
21 #[cfg(feature = "curl")]
22 pub use curl::CurlHttpTransport;
23 
24 #[cfg(feature = "surf")]
25 mod surf;
26 #[cfg(feature = "surf")]
27 pub use surf::SurfHttpTransport;
28 
29 #[cfg(feature = "reqwest")]
30 type DefaultTransport = ReqwestHttpTransport;
31 
32 #[cfg(all(feature = "curl", not(feature = "reqwest"), not(feature = "surf")))]
33 type DefaultTransport = CurlHttpTransport;
34 
35 #[cfg(all(feature = "surf", not(feature = "reqwest"), not(feature = "curl")))]
36 type DefaultTransport = SurfHttpTransport;
37 
38 /// The default http transport.
39 #[cfg(any(feature = "reqwest", feature = "curl", feature = "surf"))]
40 pub type HttpTransport = DefaultTransport;
41 
42 /// Creates the default HTTP transport.
43 ///
44 /// This is the default value for `transport` on the client options.  It
45 /// creates a `HttpTransport`.  If no http transport was compiled into the
46 /// library it will panic on transport creation.
47 #[derive(Clone)]
48 pub struct DefaultTransportFactory;
49 
50 impl TransportFactory for DefaultTransportFactory {
create_transport(&self, options: &ClientOptions) -> Arc<dyn Transport>51     fn create_transport(&self, options: &ClientOptions) -> Arc<dyn Transport> {
52         #[cfg(any(feature = "reqwest", feature = "curl", feature = "surf"))]
53         {
54             Arc::new(HttpTransport::new(options))
55         }
56         #[cfg(not(any(feature = "reqwest", feature = "curl", feature = "surf")))]
57         {
58             let _ = options;
59             panic!("sentry crate was compiled without transport")
60         }
61     }
62 }
63