Skip to content

Commit 52d5a4d

Browse files
committed
fmt
1 parent 5d2268a commit 52d5a4d

3 files changed

Lines changed: 24 additions & 16 deletions

File tree

src/client/http/aliases.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
},
1414
core::body::Incoming,
1515
error::BoxError,
16-
redirect::RedirectPolicy,
16+
redirect::FollowRedirectPolicy,
1717
};
1818

1919
#[cfg(not(feature = "cookies"))]
@@ -54,8 +54,10 @@ pub type ResponseBody = TimeoutBody<tower_http::decompression::DecompressionBody
5454
)))]
5555
pub type ResponseBody = TimeoutBody<Incoming>;
5656

57-
pub type RedirectLayer =
58-
FollowRedirect<CookieLayer<ResponseBodyTimeout<Decompression<ClientService>>>, RedirectPolicy>;
57+
pub type RedirectLayer = FollowRedirect<
58+
CookieLayer<ResponseBodyTimeout<Decompression<ClientService>>>,
59+
FollowRedirectPolicy,
60+
>;
5961

6062
pub type CoreResponseFuture = crate::core::client::ResponseFuture;
6163

src/client/http/mod.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ use crate::{
6161
dns::{DnsResolverWithOverrides, DynResolver, Resolve, gai::GaiResolver},
6262
error::{self, BoxError, Error},
6363
proxy::Matcher as ProxyMatcher,
64-
redirect,
64+
redirect::{self, FollowRedirectPolicy, Policy as RedirectPolicy},
6565
tls::{AlpnProtocol, CertStore, Identity, KeyLogPolicy, TlsConnectorBuilder, TlsVersion},
6666
};
6767

@@ -130,7 +130,7 @@ struct Config {
130130
tcp_user_timeout: Option<Duration>,
131131
proxies: Vec<ProxyMatcher>,
132132
auto_sys_proxy: bool,
133-
redirect_policy: redirect::Policy,
133+
redirect_policy: RedirectPolicy,
134134
referer: bool,
135135
timeout: Option<Duration>,
136136
read_timeout: Option<Duration>,
@@ -197,7 +197,7 @@ impl ClientBuilder {
197197
tcp_user_timeout: None,
198198
proxies: Vec::new(),
199199
auto_sys_proxy: true,
200-
redirect_policy: redirect::Policy::none(),
200+
redirect_policy: RedirectPolicy::none(),
201201
referer: true,
202202
timeout: None,
203203
read_timeout: None,
@@ -252,6 +252,7 @@ impl ClientBuilder {
252252

253253
let (tls_opts, http1_opts, http2_opts) = config.transport_options.into_parts();
254254

255+
// Create the TLS connector with the provided options.
255256
let connector = {
256257
let resolver = {
257258
let mut resolver: Arc<dyn Resolve> = match config.dns_resolver {
@@ -272,6 +273,7 @@ impl ClientBuilder {
272273
DynResolver::new(resolver)
273274
};
274275

276+
// Apply http connector options
275277
let http = |http: &mut HttpConnector| {
276278
http.set_keepalive(config.tcp_keepalive);
277279
http.set_keepalive_interval(config.tcp_keepalive_interval);
@@ -284,10 +286,10 @@ impl ClientBuilder {
284286
http.set_tcp_user_timeout(config.tcp_user_timeout);
285287
};
286288

289+
// Apply tls connector options
287290
let tls = |tls: TlsConnectorBuilder| {
288291
let alpn_protocol = match config.http_version_pref {
289292
HttpVersionPref::Http1 => Some(AlpnProtocol::HTTP1),
290-
291293
HttpVersionPref::Http2 => Some(AlpnProtocol::HTTP2),
292294
_ => None,
293295
};
@@ -311,6 +313,7 @@ impl ClientBuilder {
311313
.build(tls_opts.unwrap_or_default(), config.connector_layers)?
312314
};
313315

316+
// Create client with the configured connector
314317
let client = {
315318
let http2_only = matches!(config.http_version_pref, HttpVersionPref::Http2);
316319
let mut builder = HttpClient::builder(TokioExecutor::new());
@@ -326,6 +329,7 @@ impl ClientBuilder {
326329
builder.build(connector)
327330
};
328331

332+
// Create the client with the configured service layers
329333
let client = {
330334
let service = ClientService {
331335
client,
@@ -362,13 +366,15 @@ impl ClientBuilder {
362366
.layer(CookieManagerLayer::new(config.cookie_store))
363367
.service(service);
364368

365-
let policy = redirect::RedirectPolicy::new(config.redirect_policy)
366-
.with_referer(config.referer)
367-
.with_https_only(config.https_only);
369+
let service = {
370+
let policy = FollowRedirectPolicy::new(config.redirect_policy)
371+
.with_referer(config.referer)
372+
.with_https_only(config.https_only);
368373

369-
let service = ServiceBuilder::new()
370-
.layer(FollowRedirectLayer::with_policy(policy))
371-
.service(service);
374+
ServiceBuilder::new()
375+
.layer(FollowRedirectLayer::with_policy(policy))
376+
.service(service)
377+
};
372378

373379
let service = ServiceBuilder::new()
374380
.layer(RetryLayer::new(Http2RetryPolicy::new(

src/redirect.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,14 @@ impl fmt::Display for TooManyRedirects {
261261
impl StdError for TooManyRedirects {}
262262

263263
#[derive(Clone)]
264-
pub(crate) struct RedirectPolicy {
264+
pub(crate) struct FollowRedirectPolicy {
265265
policy: RequestConfig<RequestRedirectPolicy>,
266266
referer: bool,
267267
urls: Vec<Url>,
268268
https_only: bool,
269269
}
270270

271-
impl RedirectPolicy {
271+
impl FollowRedirectPolicy {
272272
pub(crate) const fn new(policy: Policy) -> Self {
273273
Self {
274274
policy: RequestConfig::new(Some(policy)),
@@ -301,7 +301,7 @@ fn make_referer(next: &Url, previous: &Url) -> Option<HeaderValue> {
301301
referer.as_str().parse().ok()
302302
}
303303

304-
impl policy::Policy<Body, BoxError> for RedirectPolicy {
304+
impl policy::Policy<Body, BoxError> for FollowRedirectPolicy {
305305
fn redirect(&mut self, attempt: &policy::Attempt<'_>) -> Result<policy::Action, BoxError> {
306306
// Parse the next URL from the attempt.
307307
let previous_url = IntoUrlSealed::into_url(attempt.previous().to_string())?;

0 commit comments

Comments
 (0)