1
- use futures:: { Future , Poll } ;
2
- use h2;
1
+ use futures:: Poll ;
3
2
use http;
4
- use http:: header:: CONTENT_LENGTH ;
5
3
use std:: fmt;
6
4
use std:: marker:: PhantomData ;
7
5
use std:: time:: Duration ;
@@ -11,8 +9,10 @@ use svc;
11
9
12
10
extern crate linkerd2_router;
13
11
14
- pub use self :: linkerd2_router:: { Recognize , Router } ;
12
+ pub use self :: linkerd2_router:: { error , Recognize , Router } ;
15
13
14
+ // compiler doesn't notice this type is used in where bounds below...
15
+ #[ allow( unused) ]
16
16
type Error = Box < dyn std:: error:: Error + Send + Sync > ;
17
17
18
18
#[ derive( Clone , Debug ) ]
49
49
inner : Router < Req , Rec , Stk > ,
50
50
}
51
51
52
- /// Catches errors from the inner future and maps them to 500 responses.
53
- pub struct ResponseFuture < F > {
54
- inner : F ,
55
- }
56
-
57
52
// === impl Config ===
58
53
59
54
impl Config {
@@ -132,27 +127,6 @@ where
132
127
}
133
128
}
134
129
135
- fn route_err_to_5xx ( e : Error ) -> http:: StatusCode {
136
- use self :: linkerd2_router:: error;
137
-
138
- if let Some ( ref r) = e. downcast_ref :: < error:: MakeRoute > ( ) {
139
- error ! ( "router error: {:?}" , r) ;
140
- http:: StatusCode :: INTERNAL_SERVER_ERROR
141
- } else if let Some ( _) = e. downcast_ref :: < error:: NotRecognized > ( ) {
142
- error ! ( "could not recognize request" ) ;
143
- http:: StatusCode :: INTERNAL_SERVER_ERROR
144
- } else if let Some ( ref c) = e. downcast_ref :: < error:: NoCapacity > ( ) {
145
- // TODO For H2 streams, we should probably signal a protocol-level
146
- // capacity change.
147
- error ! ( "router at capacity ({})" , c. 0 ) ;
148
- http:: StatusCode :: SERVICE_UNAVAILABLE
149
- } else {
150
- // Inner
151
- error ! ( "service error: {}" , e) ;
152
- http:: StatusCode :: INTERNAL_SERVER_ERROR
153
- }
154
- }
155
-
156
130
// === impl Service ===
157
131
158
132
impl < Req , Rec , Stk , B > svc:: Service < Req > for Service < Req , Rec , Stk >
@@ -165,20 +139,16 @@ where
165
139
B : Default + Send + ' static ,
166
140
{
167
141
type Response = <Router < Req , Rec , Stk > as svc:: Service < Req > >:: Response ;
168
- type Error = h2 :: Error ;
169
- type Future = ResponseFuture < < Router < Req , Rec , Stk > as svc:: Service < Req > >:: Future > ;
142
+ type Error = < Router < Req , Rec , Stk > as svc :: Service < Req > > :: Error ;
143
+ type Future = < Router < Req , Rec , Stk > as svc:: Service < Req > >:: Future ;
170
144
171
145
fn poll_ready ( & mut self ) -> Poll < ( ) , Self :: Error > {
172
- self . inner . poll_ready ( ) . map_err ( |e| {
173
- error ! ( "router failed to become ready: {:?}" , e) ;
174
- h2:: Reason :: INTERNAL_ERROR . into ( )
175
- } )
146
+ self . inner . poll_ready ( )
176
147
}
177
148
178
149
fn call ( & mut self , request : Req ) -> Self :: Future {
179
150
trace ! ( "routing..." ) ;
180
- let inner = self . inner . call ( request) ;
181
- ResponseFuture { inner }
151
+ self . inner . call ( request)
182
152
}
183
153
}
184
154
@@ -195,26 +165,3 @@ where
195
165
}
196
166
}
197
167
}
198
-
199
- // === impl ResponseFuture ===
200
-
201
- impl < F , B > Future for ResponseFuture < F >
202
- where
203
- F : Future < Item = http:: Response < B > , Error = Error > ,
204
- B : Default ,
205
- {
206
- type Item = F :: Item ;
207
- type Error = h2:: Error ;
208
-
209
- fn poll ( & mut self ) -> Poll < Self :: Item , Self :: Error > {
210
- self . inner . poll ( ) . or_else ( |e| {
211
- let response = http:: Response :: builder ( )
212
- . status ( route_err_to_5xx ( e) )
213
- . header ( CONTENT_LENGTH , "0" )
214
- . body ( B :: default ( ) )
215
- . unwrap ( ) ;
216
-
217
- Ok ( response. into ( ) )
218
- } )
219
- }
220
- }
0 commit comments