Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ serde = { version = "1.0", features = ["derive", "alloc"], optional = true, defa
serde_json = { version = "1.0", optional = true, features = ["alloc"], default-features = false }

# reqwest
reqwest = { version = "0.12", optional = true }
# `native-tls-alpn` enables ALPN on the default native-tls backend so HTTP/2
# (`h2`) can be negotiated; without it reqwest falls back to HTTP/1.1.
reqwest = { version = "0.12", optional = true, features = ["native-tls-alpn"] }
bytes = { version = "1.4", default-features = false, optional = true }

# crypto
Expand Down
9 changes: 2 additions & 7 deletions src/core/retry_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ pub enum Endpoint {
}

/// Request retry policy.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub enum RequestRetryConfiguration {
/// Requests shouldn't be tried again.
#[default]
None,

/// Retry the request after the same amount of time.
Expand Down Expand Up @@ -316,12 +317,6 @@ impl RequestRetryConfiguration {
}
}

impl Default for RequestRetryConfiguration {
fn default() -> Self {
Self::None
}
}

impl From<String> for Endpoint {
fn from(value: String) -> Self {
match value.as_str() {
Expand Down
20 changes: 18 additions & 2 deletions src/transport/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//!
//! It requires the [`reqwest` feature] to be enabled.
//!
//! Negotiates HTTP/2 when the origin supports it; otherwise uses HTTP/1.1.
//!
//! [`TransportReqwest`]: ./struct.TransportReqwest.html
//! [`PubNub API`]: https://www.pubnub.com/docs
//! [`reqwest`]: https://docs.rs/reqwest
Expand Down Expand Up @@ -37,7 +39,7 @@ use crate::{
PubNubClientBuilder,
};
use bytes::Bytes;
use log::info;
use log::{debug, info};
use reqwest::{
header::{HeaderMap, HeaderName, HeaderValue, InvalidHeaderName, InvalidHeaderValue},
StatusCode,
Expand Down Expand Up @@ -83,6 +85,8 @@ impl Transport for TransportReqwest {
);

let headers = prepare_headers(&request.headers)?;
let method = request.method.clone();
let path = request.path.clone();
#[cfg(feature = "std")]
let timeout = request.timeout;

Expand Down Expand Up @@ -116,6 +120,10 @@ impl Transport for TransportReqwest {

let headers = result.headers().clone();
let status = result.status();
debug!(
"Request completed: method={method} path={path} protocol={:?}",
result.version()
);
result
.bytes()
.await
Expand Down Expand Up @@ -341,6 +349,8 @@ pub mod blocking {
//!
//! It requires the [`reqwest` and `blocking` feature] to be enabled.
//!
//! Negotiates HTTP/2 when the origin supports it; otherwise uses HTTP/1.1.
//!
//! [`TransportReqwest`]: ./struct.TransportReqwest.html
//! [`PubNub API`]: https://www.pubnub.com/docs
//! [`reqwest`]: https://docs.rs/reqwest
Expand Down Expand Up @@ -368,7 +378,7 @@ pub mod blocking {
transport::reqwest::{create_result, extract_headers, prepare_headers, prepare_url},
PubNubClientBuilder,
};
use log::info;
use log::{debug, info};

/// This struct is used to send requests to the [`PubNub API`] using the
/// [`reqwest`] crate. It is used as the transport type for the
Expand Down Expand Up @@ -407,6 +417,8 @@ pub mod blocking {
request.method, request.headers, request_url
);
let headers = prepare_headers(&request.headers)?;
let method = request.method.clone();
let path = request.path.clone();
#[cfg(feature = "std")]
let timeout = request.timeout;

Expand Down Expand Up @@ -439,6 +451,10 @@ pub mod blocking {

let headers = result.headers().clone();
let status = result.status();
debug!(
"Request completed: method={method} path={path} protocol={:?}",
result.version()
);
result
.bytes()
.map_err(|e| PubNubError::Transport {
Expand Down
Loading