message: Refactor the default service stack
diff: @@ -411,17 +411,7 @@ impl TryFrom<Config> for Client {
  let timeout = config.timeout;
  let default_ns = config.default_ns.clone();
  - let common = ServiceBuilder::new()
  - .layer(SetBaseUriLayer::new(cluster_url))
  - .layer(SetHeadersLayer::new(default_headers))
  - .into_inner();
  -
  - #[cfg(feature = "gzip")]
  - let common = ServiceBuilder::new()
  - .layer(common)
  - .layer(tower_http::decompression::DecompressionLayer::new())
  - .into_inner();
  -
  + let client: hyper::Client<_, Body> = {
  let mut connector = HttpConnector::new();
  connector.enforce_http(false);
  @@ -433,7 +423,6 @@ impl TryFrom<Config> for Client {
  connector,
  tokio_native_tls::TlsConnector::from(config.native_tls_connector()?),
  ));
  -
  #[cfg(all(not(feature = "native-tls"), feature = "rustls-tls"))]
  let connector = hyper_rustls::HttpsConnector::from((
  connector,
  @@ -441,18 +430,24 @@ impl TryFrom<Config> for Client {
  ));
  let mut connector = TimeoutConnector::new(connector);
  - if let Some(timeout) = timeout {
  - // reqwest's timeout is applied from when the request stars connecting until
  - // the response body has finished.
  - // Setting both connect and read timeout should be close enough.
  - connector.set_connect_timeout(Some(timeout));
  - // Timeout for reading the response.
  - connector.set_read_timeout(Some(timeout));
  - }
  - let client: hyper::Client<_, Body> = hyper::Client::builder().build(connector);
  -
  - let inner = ServiceBuilder::new()
  - .layer(common)
  + connector.set_connect_timeout(timeout);
  + connector.set_read_timeout(timeout);
  +
  + hyper::Client::builder().build(connector)
  + };
  +
  + let stack = ServiceBuilder::new()
  + .layer(SetBaseUriLayer::new(cluster_url))
  + .layer(SetHeadersLayer::new(default_headers))
  + .into_inner();
  + #[cfg(feature = "gzip")]
  + let stack = ServiceBuilder::new()
  + .layer(stack)
  + .layer(tower_http::decompression::DecompressionLayer::new())
  + .into_inner();
  +
  + let service = ServiceBuilder::new()
  + .layer(stack)
  .option_layer(Authentication::try_from(&config.auth_info)?.into_layer())
  .layer(
  // Attribute names follow [Semantic Conventions].
  @@ -503,7 +498,7 @@ impl TryFrom<Config> for Client {
  }),
  )
  .service(client);
  - Ok(Self::new_with_default_ns(inner, default_ns))
  + Ok(Self::new_with_default_ns(service, default_ns))
  }
  }
  