Skip to content

Commit 6890c29

Browse files
committed
chore: apply automatic formatting (clippy)
1 parent ef36268 commit 6890c29

File tree

7 files changed

+44
-60
lines changed

7 files changed

+44
-60
lines changed

impit/src/http3.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl H3Engine {
3939
}
4040
}
4141

42-
pub async fn host_supports_h3(self: &mut Self, host: &String) -> bool {
42+
pub async fn host_supports_h3(&mut self, host: &String) -> bool {
4343
if let Some(supports_h3) = self.h3_alt_svc.get(host) {
4444
return supports_h3.to_owned();
4545
}
@@ -74,7 +74,7 @@ impl H3Engine {
7474
dns_h3_support
7575
}
7676

77-
pub fn set_h3_support(self: &mut Self, host: &String, supports_h3: bool) {
77+
pub fn set_h3_support(&mut self, host: &String, supports_h3: bool) {
7878
if self.h3_alt_svc.contains_key(host) {
7979
return;
8080
}

impit/src/http_headers/mod.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ impl HttpHeaders {
2020
}
2121
}
2222

23-
impl Into<HeaderMap> for HttpHeaders {
24-
fn into(self) -> HeaderMap {
23+
impl From<HttpHeaders> for HeaderMap {
24+
fn from(val: HttpHeaders) -> Self {
2525
let mut headers = HeaderMap::new();
2626

27-
let header_values = match self.context.browser {
27+
let header_values = match val.context.browser {
2828
Some(Browser::Chrome) => statics::CHROME_HEADERS,
2929
Some(Browser::Firefox) => statics::FIREFOX_HEADERS,
3030
None => &[],
3131
};
3232

33-
let pseudo_headers_order: &[&str] = match self.context.browser {
33+
let pseudo_headers_order: &[&str] = match val.context.browser {
3434
Some(Browser::Chrome) => statics::CHROME_PSEUDOHEADERS_ORDER.as_ref(),
3535
Some(Browser::Firefox) => statics::FIREFOX_PSEUDOHEADERS_ORDER.as_ref(),
3636
None => &[],
3737
};
3838

39-
if pseudo_headers_order.len() != 0 {
39+
if !pseudo_headers_order.is_empty() {
4040
std::env::set_var(
4141
"IMPIT_H2_PSEUDOHEADERS_ORDER",
4242
pseudo_headers_order.join(","),
@@ -47,7 +47,7 @@ impl Into<HeaderMap> for HttpHeaders {
4747

4848
// TODO: don't use HTTP2 headers for HTTP1.1
4949
for (name, impersonated_value) in header_values {
50-
let value: &str = match self.context.custom_headers.get(*name) {
50+
let value: &str = match val.context.custom_headers.get(*name) {
5151
Some(custom_value) => {
5252
used_custom_headers.push(name.to_string());
5353
custom_value.as_str()
@@ -61,17 +61,14 @@ impl Into<HeaderMap> for HttpHeaders {
6161
);
6262
}
6363

64-
self.context
65-
.custom_headers
66-
.iter()
67-
.for_each(|(name, value)| {
68-
if !used_custom_headers.contains(name) {
69-
headers.append(
70-
HeaderName::from_str(name).unwrap(),
71-
HeaderValue::from_str(value).unwrap(),
72-
);
73-
}
74-
});
64+
val.context.custom_headers.iter().for_each(|(name, value)| {
65+
if !used_custom_headers.contains(name) {
66+
headers.append(
67+
HeaderName::from_str(name).unwrap(),
68+
HeaderValue::from_str(value).unwrap(),
69+
);
70+
}
71+
});
7572

7673
headers
7774
}

impit/src/http_headers/statics.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Note that not all requests are made the same:
33
// - on forced (Ctrl+R) reloads, Chrome sets Cache-Control: max-age=0
44
// - when the URL is in the address bar (but not submitted yet), Chrome sets `Purpose: prefetch` and `Sec-Purpose: prefetch`
5-
pub static CHROME_HEADERS: &'static [(&'static str, &'static str)] = &[
5+
pub static CHROME_HEADERS: &[(&str, &str)] = &[
66
("sec-ch-ua", "\"Google Chrome\";v=\"125\", \"Chromium\";v=\"125\", \"Not.A/Brand\";v=\"24\""),
77
("sec-ch-ua-mobile", "?0"),
88
("sec-ch-ua-platform", "Linux"),
@@ -17,7 +17,7 @@ pub static CHROME_HEADERS: &'static [(&'static str, &'static str)] = &[
1717
("accept-language", "en-US,en;q=0.9"),
1818
];
1919

20-
pub static CHROME_PSEUDOHEADERS_ORDER: [&'static str; 6] = [
20+
pub static CHROME_PSEUDOHEADERS_ORDER: [&str; 6] = [
2121
":method",
2222
":authority",
2323
":scheme",
@@ -26,7 +26,7 @@ pub static CHROME_PSEUDOHEADERS_ORDER: [&'static str; 6] = [
2626
":status",
2727
];
2828

29-
pub static FIREFOX_HEADERS: &'static [(&'static str, &'static str)] = &[
29+
pub static FIREFOX_HEADERS: &[(&str, &str)] = &[
3030
("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0"),
3131
("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8"),
3232
("Accept-Language", "en,cs;q=0.7,en-US;q=0.3"),
@@ -40,7 +40,7 @@ pub static FIREFOX_HEADERS: &'static [(&'static str, &'static str)] = &[
4040
("Priority", "u=0, i"),
4141
];
4242

43-
pub static FIREFOX_PSEUDOHEADERS_ORDER: [&'static str; 6] = [
43+
pub static FIREFOX_PSEUDOHEADERS_ORDER: [&str; 6] = [
4444
":method",
4545
":path",
4646
":authority",

impit/src/impit.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl Impit {
197197
client = client.http3_prior_knowledge();
198198
}
199199

200-
if config.proxy_url.len() > 0 {
200+
if !config.proxy_url.is_empty() {
201201
client = client.proxy(
202202
reqwest::Proxy::all(&config.proxy_url)
203203
.expect("The proxy_url option should be a valid URL."),
@@ -252,20 +252,20 @@ impl Impit {
252252

253253
let protocol = url.scheme();
254254

255-
return match protocol {
255+
match protocol {
256256
"http" => Ok(url),
257257
"https" => Ok(url),
258258
_ => Err(ErrorType::UrlProtocolError),
259-
};
259+
}
260260
}
261261

262-
async fn should_use_h3(self: &mut Self, host: &String) -> bool {
262+
async fn should_use_h3(&mut self, host: &String) -> bool {
263263
if self.config.max_http_version < Version::HTTP_3 {
264264
debug!("HTTP/3 is disabled, falling back to TCP-based requests.");
265265
return false;
266266
}
267267

268-
if let None = &self.h3_engine {
268+
if self.h3_engine.is_none() {
269269
self.h3_engine = Some(H3Engine::init().await);
270270
}
271271

impit/src/request.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{collections::HashMap, time::Duration};
55
/// Unlike the [`ImpitBuilder`](crate::impit::ImpitBuilder) struct, these options are specific to a single request.
66
///
77
/// Used by the [`Impit`](crate::impit::Impit) struct's methods.
8-
#[derive(Debug, Clone)]
8+
#[derive(Debug, Clone, Default)]
99
pub struct RequestOptions {
1010
/// A `HashMap` that holds custom HTTP headers. These are added to the default headers and should never overwrite them.
1111
pub headers: HashMap<String, String>,
@@ -16,13 +16,3 @@ pub struct RequestOptions {
1616
/// If [`ImpitBuilder::with_http3`](crate::impit::ImpitBuilder::with_http3) wasn't called, this option will cause [`ErrorType::Http3Disabled`](crate::impit::ErrorType::Http3Disabled) errors.
1717
pub http3_prior_knowledge: bool,
1818
}
19-
20-
impl Default for RequestOptions {
21-
fn default() -> Self {
22-
RequestOptions {
23-
headers: HashMap::new(),
24-
timeout: None,
25-
http3_prior_knowledge: false,
26-
}
27-
}
28-
}

impit/src/response_parsing/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ pub fn decode(bytes: &Vec<u8>, encoding_prior_knowledge: Option<encoding::Encodi
9393

9494
if let Some(enc) = encoding_prior_knowledge {
9595
encoding = enc;
96-
} else if let Some(enc) = bom_sniffing(&bytes) {
96+
} else if let Some(enc) = bom_sniffing(bytes) {
9797
encoding = enc;
98-
} else if let Some(enc) = prescan_bytestream(&bytes) {
98+
} else if let Some(enc) = prescan_bytestream(bytes) {
9999
encoding = enc;
100100
}
101101

102-
return encoding
103-
.decode(&bytes, encoding::DecoderTrap::Strict)
104-
.unwrap();
102+
encoding
103+
.decode(bytes, encoding::DecoderTrap::Strict)
104+
.unwrap()
105105
}
106106

107107
/// A struct that represents the contents of the `Content-Type` header.
@@ -122,7 +122,7 @@ impl ContentType {
122122
pub fn from(content_type: &str) -> Result<Self, ()> {
123123
let parts: Vec<&str> = content_type.split("charset=").collect();
124124

125-
if parts.len() != 2 || parts[1].len() == 0 {
125+
if parts.len() != 2 || parts[1].is_empty() {
126126
return Err(());
127127
}
128128

@@ -132,8 +132,8 @@ impl ContentType {
132132
}
133133
}
134134

135-
impl Into<Option<encoding::EncodingRef>> for ContentType {
136-
fn into(self) -> Option<encoding::EncodingRef> {
137-
encoding::label::encoding_from_whatwg_label(self.charset.as_str())
135+
impl From<ContentType> for Option<encoding::EncodingRef> {
136+
fn from(val: ContentType) -> Self {
137+
encoding::label::encoding_from_whatwg_label(val.charset.as_str())
138138
}
139139
}

impit/src/tls/mod.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,15 @@ impl TlsConfigBuilder {
7979
.with_browser_emulator(&rustls_browser)
8080
.build();
8181

82-
match browser {
83-
Browser::Firefox => {
84-
crypto_provider.kx_groups = vec![
85-
X25519,
86-
SECP256R1,
87-
SECP384R1,
88-
// TODO : add SECPR521R1
89-
&ffdhe::FFDHE2048_KX_GROUP,
90-
&ffdhe::FFDHE3072_KX_GROUP,
91-
];
92-
}
93-
_ => {}
82+
if browser == Browser::Firefox {
83+
crypto_provider.kx_groups = vec![
84+
X25519,
85+
SECP256R1,
86+
SECP384R1,
87+
// TODO : add SECPR521R1
88+
&ffdhe::FFDHE2048_KX_GROUP,
89+
&ffdhe::FFDHE3072_KX_GROUP,
90+
];
9491
}
9592

9693
let mut config: rustls::ClientConfig =

0 commit comments

Comments
 (0)