Skip to content
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
48 changes: 41 additions & 7 deletions src/http.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![warn(clippy::pedantic)]
#![allow(missing_docs)]
use std::{
collections::HashMap,
Expand Down Expand Up @@ -69,6 +70,7 @@ pub enum HttpError {
}

impl HttpError {
#[must_use]
pub const fn is_retriable(&self) -> bool {
match self {
HttpError::BuildRequest { .. } | HttpError::MakeProxyConnector { .. } => false,
Expand Down Expand Up @@ -101,13 +103,17 @@ where
B::Data: Send,
B::Error: Into<crate::Error>,
{
// https://github.com/vectordotdev/vector/issues/23659
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
pub fn new(
tls_settings: impl Into<MaybeTlsSettings>,
proxy_config: &ProxyConfig,
) -> Result<Self, HttpError> {
HttpClient::new_with_custom_client(tls_settings, proxy_config, &mut Client::builder())
}

// https://github.com/vectordotdev/vector/issues/23659
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
pub fn new_with_custom_client(
tls_settings: impl Into<MaybeTlsSettings>,
proxy_config: &ProxyConfig,
Expand Down Expand Up @@ -215,6 +221,9 @@ fn default_user_agent() -> HeaderValue {
.expect("Invalid header value for user-agent!")
}

// https://github.com/vectordotdev/vector/issues/23659
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
#[allow(clippy::missing_panics_doc, reason = "Panic documentation deferred")]
pub fn build_proxy_connector(
tls_settings: MaybeTlsSettings,
proxy_config: &ProxyConfig,
Expand Down Expand Up @@ -264,6 +273,8 @@ pub fn build_proxy_connector(
Ok(proxy)
}

// https://github.com/vectordotdev/vector/issues/23659
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
pub fn build_tls_connector(
tls_settings: MaybeTlsSettings,
) -> Result<HttpsConnector<HttpConnector>, HttpError> {
Expand Down Expand Up @@ -310,6 +321,11 @@ fn tls_proxy_authority(url: Option<&str>) -> Option<(String, Option<u16>)> {
/// Build an HTTPS connector, skipping the `tls.server_name` override for connections to one of
/// `proxy_authorities`. The override must only apply to the upstream destination; applying it to a
/// proxy connection would verify the proxy certificate against the destination name.
// https://github.com/vectordotdev/vector/issues/23659
#[allow(
clippy::needless_pass_by_value,
reason = "Preserve ownership and drop timing"
)]
fn build_https_connector(
tls_settings: MaybeTlsSettings,
proxy_authorities: TlsProxyAuthorities,
Expand Down Expand Up @@ -378,6 +394,8 @@ impl<B, C: Clone> Clone for HttpClient<B, C> {
}
}

// https://github.com/vectordotdev/vector/issues/23659
#[allow(clippy::missing_fields_in_debug, reason = "Preserve diagnostic fields")]
impl<B, C> fmt::Debug for HttpClient<B, C> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("HttpClient")
Expand Down Expand Up @@ -415,7 +433,7 @@ pub enum Auth {

/// Bearer authentication.
///
/// The bearer token value (OAuth2, JWT, etc.) is passed as-is.
/// The bearer token value (OAuth 2.0, JWT, etc.) is passed as-is.
Bearer {
/// The bearer authentication token.
token: SensitiveString,
Expand All @@ -441,6 +459,8 @@ pub enum Auth {
}

pub trait MaybeAuth: Sized {
// https://github.com/vectordotdev/vector/issues/23659
#[allow(clippy::missing_errors_doc, reason = "Error documentation deferred")]
fn choose_one(&self, other: &Self) -> crate::Result<Self>;
}

Expand All @@ -456,19 +476,19 @@ impl MaybeAuth for Option<Auth> {

impl Auth {
pub fn apply<B>(&self, req: &mut Request<B>) {
self.apply_headers_map(req.headers_mut())
self.apply_headers_map(req.headers_mut());
}

pub fn apply_builder(&self, mut builder: Builder) -> Builder {
if let Some(map) = builder.headers_mut() {
self.apply_headers_map(map)
self.apply_headers_map(map);
}
builder
}

#[cfg(any(feature = "sinks-clickhouse", feature = "sinks-greptimedb_logs", test))]
pub(crate) fn apply_v1<B>(&self, request: &mut RequestV1<B>) {
self.apply_headers_map_v1(request.headers_mut())
self.apply_headers_map_v1(request.headers_mut());
}

pub fn apply_headers_map(&self, map: &mut HeaderMap) {
Expand All @@ -489,7 +509,7 @@ impl Auth {
map.insert(http::header::AUTHORIZATION, header_val);
}
Err(error) => {
error!(message = "Invalid custom auth header value.", value = %value, %error)
error!(message = "Invalid custom auth header value.", value = %value, %error);
}
}
}
Expand Down Expand Up @@ -517,7 +537,7 @@ impl Auth {
map.insert(http_1::header::AUTHORIZATION, header_val);
}
Err(error) => {
error!(message = "Invalid custom auth header value.", value = %value, %error)
error!(message = "Invalid custom auth header value.", value = %value, %error);
}
}
}
Expand All @@ -527,6 +547,8 @@ impl Auth {
}
}

// https://github.com/vectordotdev/vector/issues/23659
#[allow(clippy::missing_panics_doc, reason = "Panic documentation deferred")]
pub fn get_http_scheme_from_uri(uri: &Uri) -> &'static str {
// If there's no scheme, we just use "http" since it provides the most semantic relevance without inadvertently
// implying things it can't know i.e. returning "https" when we're not actually sure HTTPS was used.
Expand All @@ -541,9 +563,10 @@ pub fn get_http_scheme_from_uri(uri: &Uri) -> &'static str {
})
}

/// Builds a [TraceLayer] configured for a HTTP server.
/// Builds a [`TraceLayer`] configured for a HTTP server.
///
/// This layer emits HTTP specific telemetry for requests received, responses sent, and handler duration.
#[must_use]
pub fn build_http_trace_layer<T, U>(
span: Span,
) -> TraceLayer<
Expand Down Expand Up @@ -615,6 +638,11 @@ pub struct KeepaliveConfig {
pub tcp_keepalive: Option<TcpKeepaliveConfig>,
}

// https://github.com/vectordotdev/vector/issues/23659
#[allow(
clippy::unnecessary_wraps,
reason = "Preserve return type and caller contracts"
)]
const fn default_max_connection_age() -> Option<u64> {
Some(300) // 5 minutes
}
Expand Down Expand Up @@ -649,6 +677,7 @@ pub struct MaxConnectionAgeLayer {
}

impl MaxConnectionAgeLayer {
#[must_use]
pub fn new(max_connection_age: Duration, jitter_factor: f64, peer_addr: SocketAddr) -> Self {
Self {
start_reference: Instant::now(),
Expand Down Expand Up @@ -717,6 +746,8 @@ where
self.service.poll_ready(cx)
}

// https://github.com/vectordotdev/vector/issues/23659
#[allow(clippy::match_same_arms, reason = "Preserve branch-specific context")]
fn call(&mut self, req: Request<Body>) -> Self::Future {
let start_reference = self.start_reference;
let max_connection_age = self.max_connection_age;
Expand Down Expand Up @@ -796,6 +827,7 @@ pub enum ParameterValue {

impl ParameterValue {
/// Returns true if the parameter is a VRL expression.
#[must_use]
pub const fn is_vrl(&self) -> bool {
match self {
ParameterValue::String(_) => false,
Expand All @@ -804,13 +836,15 @@ impl ParameterValue {
}

/// Returns the raw string value of the parameter.
#[must_use]
pub const fn value(&self) -> &str {
match self {
ParameterValue::String(value) | ParameterValue::Typed { value, .. } => value.as_str(),
}
}

/// Consumes the `ParameterValue` and returns the owned raw string value.
#[must_use]
pub fn into_value(self) -> String {
match self {
ParameterValue::String(s) => s,
Expand Down
5 changes: 5 additions & 0 deletions src/http/client_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ struct HttpProxyConnectorV1 {
}

impl HttpProxyConnectorV1 {
// https://github.com/vectordotdev/vector/issues/23659
#[allow(
clippy::needless_pass_by_value,
reason = "Preserve ownership and drop timing"
)]
fn new(tls: MaybeTlsSettings, routes: Arc<RoutePlanner>) -> Result<Self, BoxError> {
let tls_settings = tls.tls().cloned();
let direct = https_connector(&tls, false)?;
Expand Down
10 changes: 10 additions & 0 deletions src/http/transport_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ fn no_tls() -> MaybeTlsSettings {
MaybeTlsSettings::from_config(None, false).unwrap()
}

// https://github.com/vectordotdev/vector/issues/23659
#[allow(
clippy::needless_pass_by_value,
reason = "Preserve ownership and drop timing"
)]
fn client_tls(config: TlsConfig) -> MaybeTlsSettings {
TlsSettings::from_options(Some(&config)).unwrap().into()
}
Expand Down Expand Up @@ -427,6 +432,11 @@ fn proxy_config(proxy: &TestServer, tls: bool, auth: bool) -> ProxyConfig {
}
}

// https://github.com/vectordotdev/vector/issues/23659
#[allow(
clippy::needless_pass_by_value,
reason = "Preserve ownership and drop timing"
)]
fn assert_success(response: TestResponse) {
assert_eq!(response.status, StatusCode::OK.as_u16());
assert_eq!(response.body, b"origin response");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ _schemaDefinitions: "core::option::Option<vector::http::Auth>": object: options:
bearer: """
Bearer authentication.

The bearer token value (OAuth2, JWT, etc.) is passed as-is.
The bearer token value (OAuth 2.0, JWT, etc.) is passed as-is.
"""
custom: "Custom Authorization Header Value, will be inserted into the headers as `Authorization: < value >`"
}
Expand Down
Loading