1- use super :: { server :: Http , Gateway } ;
1+ use super :: Gateway ;
22use inbound:: { GatewayAddr , GatewayDomainInvalid } ;
3- use linkerd_app_core:: { identity, io, profiles, proxy:: http, svc, tls, transport:: addrs:: * , Error } ;
3+ use linkerd_app_core:: {
4+ identity,
5+ metrics:: ServerLabel ,
6+ profiles,
7+ proxy:: {
8+ api_resolve:: { ConcreteAddr , Metadata } ,
9+ core:: Resolve ,
10+ http,
11+ } ,
12+ svc, tls,
13+ transport:: addrs:: * ,
14+ Error ,
15+ } ;
416use linkerd_app_inbound as inbound;
517use linkerd_app_outbound as outbound;
618use std:: {
@@ -34,34 +46,61 @@ pub struct Target<T = ()> {
3446struct ByRequestVersion < T > ( Target < T > ) ;
3547
3648impl Gateway {
37- /// Wrap the provided outbound HTTP stack with an HTTP server, inbound
38- /// authorization, and gateway request routing.
39- pub fn http < T , I , N , NSvc > ( & self , inner : N ) -> svc:: Stack < svc:: ArcNewTcp < Http < T > , I > >
49+ /// Wrap the provided outbound HTTP client with the inbound HTTP server,
50+ /// inbound authorization, tagged-transport gateway routing, and the
51+ /// outbound router.
52+ pub fn http < T , N , R , NSvc > (
53+ & self ,
54+ inner : N ,
55+ resolve : R ,
56+ ) -> svc:: Stack <
57+ svc:: ArcNewService <
58+ T ,
59+ impl svc:: Service <
60+ http:: Request < http:: BoxBody > ,
61+ Response = http:: Response < http:: BoxBody > ,
62+ Error = Error ,
63+ Future = impl Send ,
64+ > + Clone ,
65+ > ,
66+ >
4067 where
4168 // Target describing an inbound gateway connection.
4269 T : svc:: Param < GatewayAddr > ,
4370 T : svc:: Param < OrigDstAddr > ,
4471 T : svc:: Param < Remote < ClientAddr > > ,
72+ T : svc:: Param < ServerLabel > ,
4573 T : svc:: Param < tls:: ConditionalServerTls > ,
4674 T : svc:: Param < tls:: ClientId > ,
4775 T : svc:: Param < inbound:: policy:: AllowPolicy > ,
48- T : svc:: Param < profiles:: LookupAddr > ,
76+ T : svc:: Param < Option < profiles:: Receiver > > ,
77+ T : svc:: Param < http:: Version > ,
78+ T : svc:: Param < http:: normalize_uri:: DefaultAuthority > ,
4979 T : Clone + Send + Sync + Unpin + ' static ,
50- // Server-side socket.
51- I : io:: AsyncRead + io:: AsyncWrite + io:: PeerAddr ,
52- I : Send + Unpin + ' static ,
80+ // Endpoint resolution.
81+ R : Resolve < ConcreteAddr , Endpoint = Metadata , Error = Error > ,
5382 // HTTP outbound stack.
54- N : svc:: NewService < Target , Service = NSvc > ,
83+ N : svc:: NewService <
84+ outbound:: http:: concrete:: Endpoint <
85+ outbound:: http:: logical:: Concrete < outbound:: http:: Http > ,
86+ > ,
87+ Service = NSvc ,
88+ > ,
5589 N : Clone + Send + Sync + Unpin + ' static ,
5690 NSvc : svc:: Service <
5791 http:: Request < http:: BoxBody > ,
5892 Response = http:: Response < http:: BoxBody > ,
5993 Error = Error ,
6094 > ,
6195 NSvc : Send + Unpin + ' static ,
62- NSvc :: Future : Send + ' static ,
96+ NSvc :: Future : Send + Unpin + ' static ,
6397 {
64- let http = svc:: stack ( inner)
98+ let http = self
99+ . outbound
100+ . clone ( )
101+ . with_stack ( inner)
102+ . push_http_cached ( resolve)
103+ . into_stack ( )
65104 // Discard `T` and its associated client-specific metadata.
66105 . push_map_target ( Target :: discard_parent)
67106 // Add headers to prevent loops.
@@ -77,29 +116,27 @@ impl Gateway {
77116 } ) )
78117 // Only permit gateway traffic to endpoints for which we have
79118 // discovery information.
80- . push_filter (
81- |( _, parent) : ( _ , Http < T > ) | -> Result < _ , GatewayDomainInvalid > {
82- let target = {
83- let profile = svc:: Param :: < Option < profiles:: Receiver > > :: param ( & parent)
84- . ok_or ( GatewayDomainInvalid ) ?;
85-
86- if let Some ( profiles:: LogicalAddr ( addr) ) = profile. logical_addr ( ) {
87- outbound:: http:: Logical :: Route ( addr, profile)
88- } else if let Some ( ( addr, metadata) ) = profile. endpoint ( ) {
89- outbound:: http:: Logical :: Forward ( Remote ( ServerAddr ( addr) ) , metadata)
90- } else {
91- return Err ( GatewayDomainInvalid ) ;
92- }
93- } ;
94-
95- Ok ( Target {
96- target,
97- addr : ( * parent) . param ( ) ,
98- version : svc:: Param :: param ( & parent) ,
99- parent : ( * * parent) . clone ( ) ,
100- } )
101- } ,
102- )
119+ . push_filter ( |( _, parent) : ( _ , T ) | -> Result < _ , GatewayDomainInvalid > {
120+ let target = {
121+ let profile = svc:: Param :: < Option < profiles:: Receiver > > :: param ( & parent)
122+ . ok_or ( GatewayDomainInvalid ) ?;
123+
124+ if let Some ( profiles:: LogicalAddr ( addr) ) = profile. logical_addr ( ) {
125+ outbound:: http:: Logical :: Route ( addr, profile)
126+ } else if let Some ( ( addr, metadata) ) = profile. endpoint ( ) {
127+ outbound:: http:: Logical :: Forward ( Remote ( ServerAddr ( addr) ) , metadata)
128+ } else {
129+ return Err ( GatewayDomainInvalid ) ;
130+ }
131+ } ;
132+
133+ Ok ( Target {
134+ target,
135+ addr : parent. param ( ) ,
136+ version : parent. param ( ) ,
137+ parent,
138+ } )
139+ } )
103140 // Authorize requests to the gateway.
104141 . push ( self . inbound . authorize_http ( ) ) ;
105142
0 commit comments