Skip to content

Commit 469af1d

Browse files
author
victor
committed
transport: unify request modifiers and reduce allocations
1 parent 61bb3da commit 469af1d

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

tonic/src/transport/channel/service/request_modifiers.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
use crate::body::Body;
12
use http::{header::USER_AGENT, HeaderValue, Request, Uri};
23
use std::task::{Context, Poll};
34
use tower_service::Service;
4-
use crate::body::Body;
55

6+
/// A generic request modifier.
7+
///
8+
/// `Modifier<M, T>` wraps an inner service `T` and applies the
9+
/// modifier `M` to each outgoing `Request`.
10+
///
11+
/// This type centralizes the boilerplate for implementing
12+
/// request middleware. A modifier is closure which receives
13+
/// the request and mutates it before forwarding to the
14+
/// inner service.
615
#[derive(Debug)]
716
pub(crate) struct Modifier<M, T> {
817
modifier_fn: M,
@@ -39,7 +48,7 @@ where
3948
// and not FnOnce
4049
#[derive(Debug, Clone)]
4150
pub(crate) struct AddOrigin<'a> {
42-
origin: &'a Uri
51+
origin: &'a Uri,
4352
}
4453

4554
impl<'a> AddOrigin<'a> {
@@ -53,9 +62,7 @@ impl<'a> AddOrigin<'a> {
5362
Ok(Self { origin })
5463
}
5564

56-
pub(crate) fn into_fn(
57-
self,
58-
) -> impl FnOnce(Request<Body>) -> Request<Body> + Clone {
65+
pub(crate) fn into_fn(self) -> impl FnOnce(Request<Body>) -> Request<Body> + Clone {
5966
let http::uri::Parts {
6067
scheme, authority, ..
6168
} = self.origin.clone().into_parts();
@@ -106,9 +113,7 @@ impl UserAgent {
106113
Self { user_agent }
107114
}
108115

109-
pub(crate) fn into_fn(
110-
self,
111-
) -> impl FnOnce(Request<Body>) -> Request<Body> + Clone {
116+
pub(crate) fn into_fn(self) -> impl FnOnce(Request<Body>) -> Request<Body> + Clone {
112117
move |mut req| {
113118
use http::header::Entry;
114119

0 commit comments

Comments
 (0)