@@ -62,14 +62,11 @@ impl Config {
6262 . push_timeout ( self . connect . timeout )
6363 . push ( self :: client:: layer ( ) )
6464 . push ( reconnect:: layer ( backoff. clone ( ) ) )
65- . push_spawn_ready ( )
66- . into_new_service ( )
6765 . push ( self :: resolve:: layer ( dns, backoff) )
6866 . push_on_response ( self :: control:: balance:: layer ( ) )
69- . push ( metrics. into_layer :: < classify:: Response > ( ) )
70- . push ( self :: add_origin:: Layer :: new ( ) )
7167 . into_new_service ( )
72- . check_new_service ( )
68+ . push ( metrics. into_layer :: < classify:: Response > ( ) )
69+ . push ( self :: add_origin:: layer ( ) )
7370 . push_on_response ( svc:: layers ( ) . push_spawn_buffer ( self . buffer_capacity ) )
7471 . new_service ( self . addr )
7572 }
@@ -78,126 +75,54 @@ impl Config {
7875/// Sets the request's URI from `Config`.
7976mod add_origin {
8077 use super :: ControlAddr ;
81- use futures:: { ready, TryFuture } ;
82- use linkerd2_error:: Error ;
83- use pin_project:: pin_project;
84- use std:: future:: Future ;
78+ use linkerd2_stack:: { layer, NewService , ResultService } ;
8579 use std:: marker:: PhantomData ;
86- use std:: pin:: Pin ;
87- use std:: task:: { Context , Poll } ;
8880 use tower_request_modifier:: { Builder , RequestModifier } ;
8981
90- #[ derive( Debug ) ]
91- pub struct Layer < B > {
92- _marker : PhantomData < fn ( B ) > ,
82+ pub fn layer < M , B > ( ) -> impl layer:: Layer < M , Service = NewAddOrigin < M , B > > + Clone {
83+ layer:: mk ( |inner| NewAddOrigin {
84+ inner,
85+ _marker : PhantomData ,
86+ } )
9387 }
9488
9589 #[ derive( Debug ) ]
96- pub struct MakeAddOrigin < M , B > {
90+ pub struct NewAddOrigin < M , B > {
9791 inner : M ,
9892 _marker : PhantomData < fn ( B ) > ,
9993 }
10094
101- #[ pin_project]
102- pub struct MakeFuture < F , B > {
103- #[ pin]
104- inner : F ,
105- authority : http:: uri:: Authority ,
106- _marker : PhantomData < fn ( B ) > ,
107- }
95+ // === impl NewAddOrigin ===
10896
109- // === impl Layer ===
110-
111- impl < B > Layer < B > {
112- pub fn new ( ) -> Self {
113- Layer {
114- _marker : PhantomData ,
115- }
116- }
117- }
118-
119- impl < B > Clone for Layer < B > {
97+ impl < M : Clone , B > Clone for NewAddOrigin < M , B > {
12098 fn clone ( & self ) -> Self {
12199 Self {
100+ inner : self . inner . clone ( ) ,
122101 _marker : self . _marker ,
123102 }
124103 }
125104 }
126105
127- impl < M , B > tower:: layer:: Layer < M > for Layer < B > {
128- type Service = MakeAddOrigin < M , B > ;
129-
130- fn layer ( & self , inner : M ) -> Self :: Service {
131- Self :: Service {
132- inner,
133- _marker : PhantomData ,
134- }
135- }
136- }
137-
138- // === impl MakeAddOrigin ===
139-
140- impl < M , B > tower:: Service < ControlAddr > for MakeAddOrigin < M , B >
106+ impl < M , B > NewService < ControlAddr > for NewAddOrigin < M , B >
141107 where
142- M : tower:: Service < ControlAddr > ,
143- M :: Error : Into < Error > ,
108+ M : NewService < ControlAddr > ,
144109 {
145- type Response = RequestModifier < M :: Response , B > ;
146- type Error = Error ;
147- type Future = MakeFuture < M :: Future , B > ;
110+ type Service = ResultService < RequestModifier < M :: Service , B > , BuildError > ;
148111
149- fn poll_ready ( & mut self , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , Self :: Error > > {
150- self . inner . poll_ready ( cx) . map_err ( Into :: into)
151- }
152-
153- fn call ( & mut self , target : ControlAddr ) -> Self :: Future {
112+ fn new_service ( & mut self , target : ControlAddr ) -> Self :: Service {
154113 let authority = target. addr . to_http_authority ( ) ;
155- let inner = self . inner . call ( target) ;
156- MakeFuture {
157- inner,
158- authority,
159- _marker : PhantomData ,
160- }
161- }
162- }
163-
164- impl < M , B > Clone for MakeAddOrigin < M , B >
165- where
166- M : tower:: Service < ControlAddr > + Clone ,
167- {
168- fn clone ( & self ) -> Self {
169- Self {
170- inner : self . inner . clone ( ) ,
171- _marker : PhantomData ,
172- }
173- }
174- }
175-
176- // === impl MakeFuture ===
177-
178- impl < F , B > Future for MakeFuture < F , B >
179- where
180- F : TryFuture ,
181- F :: Error : Into < Error > ,
182- {
183- type Output = Result < RequestModifier < F :: Ok , B > , Error > ;
184-
185- fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
186- let this = self . project ( ) ;
187- let inner = ready ! ( this. inner. try_poll( cx) . map_err( Into :: into) ) ?;
188-
189- Poll :: Ready (
114+ ResultService :: from (
190115 Builder :: new ( )
191- . set_origin ( format ! ( "http://{}" , this . authority) )
192- . build ( inner)
193- . map_err ( |_| BuildError . into ( ) ) ,
116+ . set_origin ( format ! ( "http://{}" , authority) )
117+ . build ( self . inner . new_service ( target ) )
118+ . map_err ( |_| BuildError ( ( ) ) ) ,
194119 )
195120 }
196121 }
197122
198123 // XXX the request_modifier build error does not implement Error...
199124 #[ derive( Debug ) ]
200- struct BuildError ;
125+ pub struct BuildError ( ( ) ) ;
201126
202127 impl std:: error:: Error for BuildError { }
203128 impl std:: fmt:: Display for BuildError {
0 commit comments