Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fmt imports #388

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 35 additions & 26 deletions src/client/http.rs
Original file line number Diff line number Diff line change
@@ -1,51 +1,60 @@
use std::borrow::Cow;
use std::future::Future;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::num::NonZeroUsize;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};
use std::time::Duration;
use std::{collections::HashMap, convert::TryInto, net::SocketAddr};
use std::{fmt, str};

use crate::connect::sealed::{Conn, Unnameable};
use crate::error::BoxError;
use crate::util::client::{
Http1Builder, Http2Builder, InnerRequest, NetworkScheme, NetworkSchemeBuilder,
use crate::connect::{
sealed::{Conn, Unnameable},
BoxedConnectorLayer, BoxedConnectorService, Connector, ConnectorBuilder,
};
use crate::util::rt::tokio::TokioTimer;
use crate::util::{self, client::connect::HttpConnector, client::Builder, rt::TokioExecutor};
use bytes::Bytes;
use http::header::{
Entry, HeaderMap, HeaderValue, ACCEPT_ENCODING, CONTENT_ENCODING, CONTENT_LENGTH, CONTENT_TYPE,
LOCATION, PROXY_AUTHORIZATION, RANGE, REFERER, TRANSFER_ENCODING, USER_AGENT,
};
use http::uri::Scheme;
use http::{HeaderName, Uri, Version};
use pin_project_lite::pin_project;
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
use tokio::time::Sleep;
use tower::util::BoxCloneSyncServiceLayer;
use tower::{Layer, Service};

use super::decoder::Accepts;
use super::request::{Request, RequestBuilder};
use super::response::Response;
use super::{Body, HttpContext, HttpContextProvider};
use crate::connect::{BoxedConnectorLayer, BoxedConnectorService, Connector, ConnectorBuilder};
#[cfg(feature = "cookies")]
use crate::cookie;
#[cfg(feature = "hickory-dns")]
use crate::dns::hickory::{HickoryDnsResolver, LookupIpStrategy};
use crate::dns::{gai::GaiResolver, DnsResolverWithOverrides, DynResolver, Resolve};
use crate::error::BoxError;
use crate::into_url::try_uri;
use crate::util::{
self,
client::{
connect::HttpConnector, Builder, Http1Builder, Http2Builder, InnerRequest, NetworkScheme,
NetworkSchemeBuilder,
},
rt::{tokio::TokioTimer, TokioExecutor},
};
use crate::{cfg_bindable_device, error, impl_debug, Http1Config, Http2Config};
use crate::{
redirect,
tls::{AlpnProtos, BoringTlsConnector, RootCertStore, TlsVersion},
};
use crate::{IntoUrl, Method, Proxy, StatusCode, Url};

use super::decoder::Accepts;
use super::request::{Request, RequestBuilder};
use super::response::Response;
use super::{Body, HttpContext, HttpContextProvider};

use bytes::Bytes;
use http::{
header::{
Entry, HeaderMap, HeaderValue, ACCEPT_ENCODING, CONTENT_ENCODING, CONTENT_LENGTH,
CONTENT_TYPE, LOCATION, PROXY_AUTHORIZATION, RANGE, REFERER, TRANSFER_ENCODING, USER_AGENT,
},
uri::Scheme,
HeaderName, Uri, Version,
};
use log::{debug, trace};
use pin_project_lite::pin_project;

use tokio::time::Sleep;
use tower::util::BoxCloneSyncServiceLayer;
use tower::{Layer, Service};

type HyperResponseFuture = util::client::ResponseFuture;

Expand Down
12 changes: 6 additions & 6 deletions src/imp/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ macro_rules! mod_generator {
use super::*;

#[inline(always)]
pub fn http_config(os_choice: ImpersonateOS, skip_http2: bool, skip_headers: bool) -> HttpContext {
pub fn http_context(option: ImpersonateOption) -> HttpContext {
#[allow(unreachable_patterns)]
match os_choice {
match option.impersonate_os {
$(
ImpersonateOS::$other_os => HttpContext::builder()
.tls_config($tls_config)
.http2_config(conditional_http2!(skip_http2, $http2_config))
.default_headers(conditional_headers!(skip_headers, || {
.http2_config(conditional_http2!(option.skip_http2, $http2_config))
.default_headers(conditional_headers!(option.skip_headers, || {
$header_initializer(
$other_sec_ch_ua,
$other_ua,
Expand All @@ -32,8 +32,8 @@ macro_rules! mod_generator {
)*
_ => HttpContext::builder()
.tls_config($tls_config)
.http2_config(conditional_http2!(skip_http2, $http2_config))
.default_headers(conditional_headers!(skip_headers, || {
.http2_config(conditional_http2!(option.skip_http2, $http2_config))
.default_headers(conditional_headers!(option.skip_headers, || {
$header_initializer(
$default_sec_ch_ua,
$default_ua,
Expand Down
12 changes: 6 additions & 6 deletions src/imp/firefox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ macro_rules! mod_generator {
use super::*;

#[inline(always)]
pub fn http_config(os_choice: ImpersonateOS, skip_http2: bool, skip_headers: bool) -> HttpContext {
pub fn http_context(option: ImpersonateOption) -> HttpContext {
#[allow(unreachable_patterns)]
match os_choice {
match option.impersonate_os {
$(
ImpersonateOS::$other_os => {
HttpContext::builder()
.tls_config($tls_config)
.http2_config(conditional_http2!(skip_http2, $http2_config))
.default_headers(conditional_headers!(skip_headers, $header_initializer, $other_ua))
.http2_config(conditional_http2!(option.skip_http2, $http2_config))
.default_headers(conditional_headers!(option.skip_headers, $header_initializer, $other_ua))
.build()
}
),*
_ => {
HttpContext::builder()
.tls_config($tls_config)
.http2_config(conditional_http2!(skip_http2, $http2_config))
.default_headers(conditional_headers!(skip_headers, $header_initializer, $default_ua))
.http2_config(conditional_http2!(option.skip_http2, $http2_config))
.default_headers(conditional_headers!(option.skip_headers, $header_initializer, $default_ua))
.build()
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/imp/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ macro_rules! join {
}

macro_rules! impersonate_match {
($ver:expr, $os:expr, $skip_http2:expr, $skip_headers:expr, $($variant:pat => $path:expr),+) => {
($ver:expr, $opt:expr, $($variant:pat => $path:expr),+) => {
match $ver {
$(
$variant => $path($os, $skip_http2, $skip_headers),
$variant => $path($opt),
)+
}
}
Expand Down
124 changes: 61 additions & 63 deletions src/imp/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Impersonate http_config for different browsers.
//! Impersonate http_context for different browsers.
#![allow(missing_debug_implementations)]
#![allow(missing_docs)]

Expand All @@ -12,15 +12,14 @@ mod safari;
use crate::{HttpContext, HttpContextProvider};
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;
use Impersonate::*;

use chrome::*;
use firefox::*;
use okhttp::*;
use safari::*;

mod impersonate_imports {
pub use crate::{Http2Config, HttpContext, ImpersonateOS};
pub use crate::{Http2Config, HttpContext, ImpersonateOS, ImpersonateOption};
pub use http::{
header::{ACCEPT, ACCEPT_LANGUAGE, UPGRADE_INSECURE_REQUESTS, USER_AGENT},
HeaderMap, HeaderName, HeaderValue,
Expand Down Expand Up @@ -278,66 +277,65 @@ impl HttpContextProvider for ImpersonateOption {
fn context(self) -> HttpContext {
impersonate_match!(
self.impersonate,
self.impersonate_os,
self.skip_http2,
self.skip_headers,
Chrome100 => v100::http_config,
Chrome101 => v101::http_config,
Chrome104 => v104::http_config,
Chrome105 => v105::http_config,
Chrome106 => v106::http_config,
Chrome107 => v107::http_config,
Chrome108 => v108::http_config,
Chrome109 => v109::http_config,
Chrome114 => v114::http_config,
Chrome116 => v116::http_config,
Chrome117 => v117::http_config,
Chrome118 => v118::http_config,
Chrome119 => v119::http_config,
Chrome120 => v120::http_config,
Chrome123 => v123::http_config,
Chrome124 => v124::http_config,
Chrome126 => v126::http_config,
Chrome127 => v127::http_config,
Chrome128 => v128::http_config,
Chrome129 => v129::http_config,
Chrome130 => v130::http_config,
Chrome131 => v131::http_config,

SafariIos17_2 => safari_ios_17_2::http_config,
SafariIos17_4_1 => safari_ios_17_4_1::http_config,
SafariIos16_5 => safari_ios_16_5::http_config,
Safari15_3 => safari15_3::http_config,
Safari15_5 => safari15_5::http_config,
Safari15_6_1 => safari15_6_1::http_config,
Safari16 => safari16::http_config,
Safari16_5 => safari16_5::http_config,
Safari17_0 => safari17_0::http_config,
Safari17_2_1 => safari17_2_1::http_config,
Safari17_4_1 => safari17_4_1::http_config,
Safari17_5 => safari17_5::http_config,
Safari18 => safari18::http_config,
SafariIPad18 => safari_ipad_18::http_config,
Safari18_2 => safari18_2::http_config,
SafariIos18_1_1 => safari_ios_18_1_1::http_config,

OkHttp3_9 => okhttp3_9::http_config,
OkHttp3_11 => okhttp3_11::http_config,
OkHttp3_13 => okhttp3_13::http_config,
OkHttp3_14 => okhttp3_14::http_config,
OkHttp4_9 => okhttp4_9::http_config,
OkHttp4_10 => okhttp4_10::http_config,
OkHttp5 => okhttp5::http_config,

Edge101 => edge101::http_config,
Edge122 => edge122::http_config,
Edge127 => edge127::http_config,
Edge131 => edge131::http_config,

Firefox109 => ff109::http_config,
Firefox117 => ff117::http_config,
Firefox128 => ff128::http_config,
Firefox133 => ff133::http_config
self,

Impersonate::Chrome100 => v100::http_context,
Impersonate::Chrome101 => v101::http_context,
Impersonate::Chrome104 => v104::http_context,
Impersonate::Chrome105 => v105::http_context,
Impersonate::Chrome106 => v106::http_context,
Impersonate::Chrome107 => v107::http_context,
Impersonate::Chrome108 => v108::http_context,
Impersonate::Chrome109 => v109::http_context,
Impersonate::Chrome114 => v114::http_context,
Impersonate::Chrome116 => v116::http_context,
Impersonate::Chrome117 => v117::http_context,
Impersonate::Chrome118 => v118::http_context,
Impersonate::Chrome119 => v119::http_context,
Impersonate::Chrome120 => v120::http_context,
Impersonate::Chrome123 => v123::http_context,
Impersonate::Chrome124 => v124::http_context,
Impersonate::Chrome126 => v126::http_context,
Impersonate::Chrome127 => v127::http_context,
Impersonate::Chrome128 => v128::http_context,
Impersonate::Chrome129 => v129::http_context,
Impersonate::Chrome130 => v130::http_context,
Impersonate::Chrome131 => v131::http_context,

Impersonate::SafariIos17_2 => safari_ios_17_2::http_context,
Impersonate::SafariIos17_4_1 => safari_ios_17_4_1::http_context,
Impersonate::SafariIos16_5 => safari_ios_16_5::http_context,
Impersonate::Safari15_3 => safari15_3::http_context,
Impersonate::Safari15_5 => safari15_5::http_context,
Impersonate::Safari15_6_1 => safari15_6_1::http_context,
Impersonate::Safari16 => safari16::http_context,
Impersonate::Safari16_5 => safari16_5::http_context,
Impersonate::Safari17_0 => safari17_0::http_context,
Impersonate::Safari17_2_1 => safari17_2_1::http_context,
Impersonate::Safari17_4_1 => safari17_4_1::http_context,
Impersonate::Safari17_5 => safari17_5::http_context,
Impersonate::Safari18 => safari18::http_context,
Impersonate::SafariIPad18 => safari_ipad_18::http_context,
Impersonate::Safari18_2 => safari18_2::http_context,
Impersonate::SafariIos18_1_1 => safari_ios_18_1_1::http_context,

Impersonate::OkHttp3_9 => okhttp3_9::http_context,
Impersonate::OkHttp3_11 => okhttp3_11::http_context,
Impersonate::OkHttp3_13 => okhttp3_13::http_context,
Impersonate::OkHttp3_14 => okhttp3_14::http_context,
Impersonate::OkHttp4_9 => okhttp4_9::http_context,
Impersonate::OkHttp4_10 => okhttp4_10::http_context,
Impersonate::OkHttp5 => okhttp5::http_context,

Impersonate::Edge101 => edge101::http_context,
Impersonate::Edge122 => edge122::http_context,
Impersonate::Edge127 => edge127::http_context,
Impersonate::Edge131 => edge131::http_context,

Impersonate::Firefox109 => ff109::http_context,
Impersonate::Firefox117 => ff117::http_context,
Impersonate::Firefox128 => ff128::http_context,
Impersonate::Firefox133 => ff133::http_context
)
}
}
Expand Down
10 changes: 3 additions & 7 deletions src/imp/okhttp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ macro_rules! mod_generator {
use super::*;

#[inline(always)]
pub fn http_config(
_: ImpersonateOS,
skip_http2: bool,
skip_headers: bool,
) -> HttpContext {
pub fn http_context(option: ImpersonateOption) -> HttpContext {
HttpContext::builder()
.tls_config(tls_config!($cipher_list))
.http2_config(conditional_http2!(skip_http2, http2_config!()))
.http2_config(conditional_http2!(option.skip_http2, http2_config!()))
.default_headers(conditional_headers!(
skip_headers,
option.skip_headers,
super::header_initializer,
$ua
))
Expand Down
14 changes: 7 additions & 7 deletions src/imp/safari.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ macro_rules! mod_generator {
use super::*;

#[inline(always)]
pub fn http_config(
_: ImpersonateOS,
skip_http2: bool,
skip_headers: bool,
) -> HttpContext {
pub fn http_context(option: ImpersonateOption) -> HttpContext {
HttpContext::builder()
.tls_config($tls_config)
.http2_config(conditional_http2!(skip_http2, $http2_config))
.default_headers(conditional_headers!(skip_headers, $header_initializer, $ua))
.http2_config(conditional_http2!(option.skip_http2, $http2_config))
.default_headers(conditional_headers!(
option.skip_headers,
$header_initializer,
$ua
))
.build()
}
}
Expand Down
Loading