Skip to content

Commit

Permalink
Publicize Connect trait access (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescarterbell committed Sep 18, 2024
1 parent 69f150e commit 16bc0d6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ntex/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ntex"
version = "2.4.0"
version = "2.4.1"
authors = ["ntex contributors <[email protected]>"]
description = "Framework for composable network services"
readme = "README.md"
Expand Down
12 changes: 12 additions & 0 deletions ntex/src/http/client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ impl ClientBuilder {
self
}

/// Use custom connection. Mainly used for mocking connections.
/// # Note
/// This overrides anything set with [`Self::connector`].
#[doc(hidden)]
pub fn connection(
mut self,
connection: impl super::connect::Connect + 'static,
) -> Self {
self.config.connector = Box::new(connection);
self
}

/// Set request timeout.
///
/// Request timeout is the total time before a response must be received.
Expand Down
3 changes: 2 additions & 1 deletion ntex/src/http/client/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ where
}
}

pub(super) trait Connect: fmt::Debug {
#[doc(hidden)]
pub trait Connect: fmt::Debug {
fn send_request(
&self,
head: RequestHeadType,
Expand Down
13 changes: 7 additions & 6 deletions ntex/src/http/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use std::rc::Rc;

mod builder;
mod connect;
pub mod connect;
mod connection;
mod connector;
pub mod error;
Expand Down Expand Up @@ -74,12 +74,13 @@ pub struct Connect {
pub struct Client(Rc<ClientConfig>);

#[derive(Debug)]
pub(crate) struct ClientConfig {
#[doc(hidden)]
pub struct ClientConfig {
pub(self) connector: Box<dyn HttpConnect>,
pub(self) headers: HeaderMap,
pub(self) timeout: Millis,
pub(self) response_pl_limit: usize,
pub(self) response_pl_timeout: Millis,
pub headers: HeaderMap,
pub timeout: Millis,
pub response_pl_limit: usize,
pub response_pl_timeout: Millis,
}

impl Default for ClientConfig {
Expand Down
7 changes: 2 additions & 5 deletions ntex/src/http/client/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,8 @@ impl HttpMessage for ClientResponse {

impl ClientResponse {
/// Create new client response instance
pub(crate) fn new(
head: ResponseHead,
payload: Payload,
config: Rc<ClientConfig>,
) -> Self {
#[doc(hidden)]
pub fn new(head: ResponseHead, payload: Payload, config: Rc<ClientConfig>) -> Self {
ClientResponse {
head,
payload,
Expand Down

0 comments on commit 16bc0d6

Please sign in to comment.