rquest_util/emulation/device/
macros.rs1#[macro_export]
2macro_rules! conditional_http2 {
3 ($skip_http2:expr, $http2:expr) => {
4 if $skip_http2 { None } else { Some($http2) }
5 };
6}
7
8#[macro_export]
9macro_rules! header_chrome_sec_ch_ua {
10 ($headers:expr, $ua:expr, $platform:expr, $is_mobile:expr) => {
11 let mobile = if $is_mobile { "?1" } else { "?0" };
12 $headers.insert("sec-ch-ua", HeaderValue::from_static($ua));
13 $headers.insert("sec-ch-ua-mobile", HeaderValue::from_static(mobile));
14 $headers.insert("sec-ch-ua-platform", HeaderValue::from_static($platform));
15 };
16}
17
18#[macro_export]
19macro_rules! header_chrome_sec_fetch {
20 ($headers:expr) => {
21 $headers.insert("sec-fetch-dest", HeaderValue::from_static("document"));
22 $headers.insert("sec-fetch-mode", HeaderValue::from_static("navigate"));
23 $headers.insert("sec-fetch-site", HeaderValue::from_static("none"));
24 };
25}
26
27#[macro_export]
28macro_rules! header_chrome_ua {
29 ($headers:expr, $ua:expr) => {
30 $headers.insert(UPGRADE_INSECURE_REQUESTS, HeaderValue::from_static("1"));
31 $headers.insert(USER_AGENT, HeaderValue::from_static($ua));
32 };
33}
34
35#[macro_export]
36macro_rules! header_chrome_accpet {
37 ($headers:expr) => {
38 $headers.insert(ACCEPT, HeaderValue::from_static("text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"));
39 #[cfg(all(feature = "gzip", feature = "deflate", feature = "brotli"))]
40 $headers.insert(
41 ACCEPT_ENCODING,
42 HeaderValue::from_static("gzip, deflate, br"),
43 );
44 $headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.9"));
45 };
46 (zstd, $headers:expr) => {
47 $headers.insert(ACCEPT, HeaderValue::from_static("text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"));
48 #[cfg(all(
49 feature = "gzip",
50 feature = "deflate",
51 feature = "brotli",
52 feature = "zstd"
53 ))]
54 $headers.insert(
55 ACCEPT_ENCODING,
56 HeaderValue::from_static("gzip, deflate, br, zstd"),
57 );
58 $headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.9"));
59 }
60}
61
62#[macro_export]
63macro_rules! header_firefox_sec_fetch {
64 ($headers:expr) => {
65 $headers.insert("sec-fetch-dest", HeaderValue::from_static("document"));
66 $headers.insert("sec-fetch-mode", HeaderValue::from_static("navigate"));
67 $headers.insert("sec-fetch-site", HeaderValue::from_static("none"));
68 };
69}
70
71#[macro_export]
72macro_rules! header_firefox_accept {
73 ($headers:expr) => {
74 $headers.insert(
75 ACCEPT,
76 HeaderValue::from_static(
77 "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
78 ),
79 );
80 #[cfg(all(feature = "gzip", feature = "deflate", feature = "brotli"))]
81 $headers.insert(
82 ACCEPT_ENCODING,
83 HeaderValue::from_static("gzip, deflate, br"),
84 );
85 $headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.5"));
86 };
87 (zstd, $headers:expr) => {
88 $headers.insert(
89 ACCEPT,
90 HeaderValue::from_static(
91 "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
92 ),
93 );
94 #[cfg(all(
95 feature = "gzip",
96 feature = "deflate",
97 feature = "brotli",
98 feature = "zstd"
99 ))]
100 $headers.insert(
101 ACCEPT_ENCODING,
102 HeaderValue::from_static("gzip, deflate, br, zstd"),
103 );
104 $headers.insert(ACCEPT_LANGUAGE, HeaderValue::from_static("en-US,en;q=0.5"));
105 };
106}
107
108#[macro_export]
109macro_rules! header_firefox_ua {
110 ($headers:expr, $ua:expr) => {
111 $headers.insert(
112 HeaderName::from_static("te"),
113 HeaderValue::from_static("trailers"),
114 );
115 $headers.insert(UPGRADE_INSECURE_REQUESTS, HeaderValue::from_static("1"));
116 $headers.insert(USER_AGENT, HeaderValue::from_static($ua));
117 };
118}
119
120#[macro_export]
121macro_rules! join {
122 ($sep:expr, $first:expr $(, $rest:expr)*) => {
123 concat!($first $(, $sep, $rest)*)
124 };
125}