leyline/core/session/
mod.rs1#![forbid(unsafe_code)]
2mod builder;
3pub(crate) mod decompress;
4pub(crate) mod execute;
5mod header_merge;
6mod helpers;
7mod identity;
8mod proxy;
9mod transport_policy;
10#[cfg(feature = "websocket")]
11mod websocket;
12
13#[cfg(test)]
14mod tests;
15
16pub use builder::SessionBuilder;
17pub use identity::{Identity, SessionIdentity};
18#[cfg(feature = "websocket")]
19pub use websocket::WebSocketBuilder;
20
21use std::sync::{Arc, Mutex};
22
23use url::Url;
24
25use crate::cookie::Jar;
26#[cfg(feature = "websocket")]
27use crate::core::WebSocketConfig;
28use crate::core::retry::RetryPolicy;
29use crate::core::{CompressionConfig, ProxyConfig, RedirectPolicy, TimeoutConfig};
30use crate::h2::H2Config;
31use crate::pool::Pool;
32use crate::profile::{Browser, ChromiumBrand, HeaderStyle, Platform};
33use crate::tls::FingerprintConnector;
34use crate::tls::TlsTrustConfig;
35
36#[derive(Debug, Clone, Copy, PartialEq, Eq)]
37#[non_exhaustive]
38pub enum ProtocolPolicy {
39 Auto,
40 Http1,
41 Http2,
42 #[cfg(feature = "http3")]
43 Http3,
44 #[cfg(feature = "http3")]
45 Race,
46}
47
48impl ProtocolPolicy {
49 #[cfg(feature = "http3")]
50 pub(crate) fn requires_h3(self) -> bool {
51 matches!(self, Self::Http3 | Self::Race)
52 }
53}
54
55#[derive(Clone)]
56pub struct Session {
57 inner: Arc<SessionInner>,
58}
59
60#[derive(Clone)]
61pub(crate) struct SessionInner {
62 browser: Option<Browser>,
63 impersonates: bool,
64 header_style: HeaderStyle,
65 identity: Option<Identity>,
66 platform: Platform,
67 brand: ChromiumBrand,
68 user_agent: String,
69 sec_ch_ua: String,
70 accept_language: String,
71 header_order: Option<Vec<String>>,
72 default_headers: Vec<(String, String)>,
73 bearer: Option<builder::BearerToken>,
74 proxy_config: ProxyConfig,
75 timeouts: TimeoutConfig,
76 redirect_policy: RedirectPolicy,
77 compression: CompressionConfig,
78 #[cfg(feature = "websocket")]
79 websocket_config: WebSocketConfig,
80 https_only: bool,
81 cookie_jar: Jar,
82 connector: FingerprintConnector,
83 h2_config: H2Config,
84 pool: Arc<Pool>,
85 shutdown: tokio_util::sync::CancellationToken,
86 audit_tls: Option<Arc<crate::audit::AuditTlsCache>>,
87 protocol_policy: ProtocolPolicy,
88 default_retry: RetryPolicy,
89 #[cfg(feature = "http3")]
90 h3_config: Option<crate::quic::H3Config>,
91 tls_trust: TlsTrustConfig,
92 profile: Arc<crate::profile::BrowserProfile>,
93 base_url: Option<Url>,
94 languages: Option<Vec<String>>,
95 host_limits: crate::core::config::HostLimits,
96 #[cfg(feature = "html")]
97 crawl_limits: Arc<std::sync::OnceLock<crate::core::config::HostLimits>>,
98 #[cfg(feature = "html")]
99 crawl_pace: Option<crate::core::config::HostLimits>,
100 proxy_pool: Option<crate::core::proxy_pool::ProxyPool>,
101 trace: Option<Arc<dyn crate::trace::Trace>>,
102 #[expect(
103 clippy::type_complexity,
104 reason = "The shared cache retains raw input and a parsed URL shared by active requests"
105 )]
106 url_cache: Arc<Mutex<Option<(String, Arc<Url>)>>>,
107}