Skip to content

Commit

Permalink
Agent::run to also execute middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
algesten committed Sep 28, 2024
1 parent 770bdf7 commit 4797a09
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
13 changes: 2 additions & 11 deletions src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::config::RequestLevelConfig;
use crate::middleware::MiddlewareNext;
use crate::pool::ConnectionPool;
use crate::resolver::{DefaultResolver, Resolver};
use crate::run::run;
use crate::send_body::AsSendBody;
use crate::transport::{Connector, DefaultConnector};
use crate::{Config, Error, RequestBuilder, SendBody};
Expand Down Expand Up @@ -133,10 +132,10 @@ impl Agent {
let body = body.as_body();
let request = Request::from_parts(parts, ());

self.do_run(request, body)
self.run_via_middleware(request, body)
}

pub(crate) fn run_middleware(
pub(crate) fn run_via_middleware(
&self,
request: Request<()>,
body: SendBody,
Expand All @@ -148,14 +147,6 @@ impl Agent {
next.handle(request)
}

pub(crate) fn do_run(
&self,
request: Request<()>,
body: SendBody,
) -> Result<Response<Body>, Error> {
run(self, request, body)
}

/// Get the config for this agent.
pub fn config(&self) -> &Config {
&self.config
Expand Down
3 changes: 2 additions & 1 deletion src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::fmt;
use std::sync::Arc;

use crate::run::run;
use crate::{Agent, Body, Error, SendBody};

/// Chained processing of request (and response).
Expand Down Expand Up @@ -212,7 +213,7 @@ impl<'a> MiddlewareNext<'a> {
// When chain is over, call the actual do_run on agent.
let (parts, body) = request.into_parts();
let request = http::Request::from_parts(parts, ());
self.agent.do_run(request, body)
run(self.agent, request, body)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl RequestBuilder<WithBody> {
}

fn do_call(agent: Agent, request: Request<()>, body: SendBody) -> Result<Response<Body>, Error> {
let response = agent.run_middleware(request, body)?;
let response = agent.run_via_middleware(request, body)?;
Ok(response)
}

Expand Down

0 comments on commit 4797a09

Please sign in to comment.