1
+ use core:: fmt;
1
2
use std:: future:: Future ;
2
3
use std:: pin:: Pin ;
3
4
use std:: task:: { ready, Context , Poll } ;
61
62
}
62
63
}
63
64
64
- impl < S > Service < Request < BoxBody > > for GrpcWebService < S >
65
+ impl < S , B > Service < Request < B > > for GrpcWebService < S >
65
66
where
66
67
S : Service < Request < BoxBody > , Response = Response < BoxBody > > ,
68
+ B : http_body:: Body < Data = bytes:: Bytes > + Send + ' static ,
69
+ B :: Error : Into < crate :: BoxError > + fmt:: Display ,
67
70
{
68
71
type Response = S :: Response ;
69
72
type Error = S :: Error ;
73
76
self . inner . poll_ready ( cx)
74
77
}
75
78
76
- fn call ( & mut self , req : Request < BoxBody > ) -> Self :: Future {
79
+ fn call ( & mut self , req : Request < B > ) -> Self :: Future {
77
80
match RequestKind :: new ( req. headers ( ) , req. method ( ) , req. version ( ) ) {
78
81
// A valid grpc-web request, regardless of HTTP version.
79
82
//
@@ -113,7 +116,7 @@ where
113
116
debug ! ( kind = "other h2" , content_type = ?req. headers( ) . get( header:: CONTENT_TYPE ) ) ;
114
117
ResponseFuture {
115
118
case : Case :: Other {
116
- future : self . inner . call ( req) ,
119
+ future : self . inner . call ( req. map ( tonic :: body :: boxed ) ) ,
117
120
} ,
118
121
}
119
122
}
@@ -194,7 +197,11 @@ impl<'a> RequestKind<'a> {
194
197
// Mutating request headers to conform to a gRPC request is not really
195
198
// necessary for us at this point. We could remove most of these except
196
199
// maybe for inserting `header::TE`, which tonic should check?
197
- fn coerce_request ( mut req : Request < BoxBody > , encoding : Encoding ) -> Request < BoxBody > {
200
+ fn coerce_request < B > ( mut req : Request < B > , encoding : Encoding ) -> Request < BoxBody >
201
+ where
202
+ B : http_body:: Body < Data = bytes:: Bytes > + Send + ' static ,
203
+ B :: Error : Into < crate :: BoxError > + fmt:: Display ,
204
+ {
198
205
req. headers_mut ( ) . remove ( header:: CONTENT_LENGTH ) ;
199
206
200
207
req. headers_mut ( )
@@ -211,7 +218,11 @@ fn coerce_request(mut req: Request<BoxBody>, encoding: Encoding) -> Request<BoxB
211
218
req. map ( |b| GrpcWebCall :: request ( b, encoding) . boxed_unsync ( ) )
212
219
}
213
220
214
- fn coerce_response ( res : Response < BoxBody > , encoding : Encoding ) -> Response < BoxBody > {
221
+ fn coerce_response < B > ( res : Response < B > , encoding : Encoding ) -> Response < BoxBody >
222
+ where
223
+ B : http_body:: Body < Data = bytes:: Bytes > + Send + ' static ,
224
+ B :: Error : Into < crate :: BoxError > + fmt:: Display ,
225
+ {
215
226
let mut res = res
216
227
. map ( |b| GrpcWebCall :: response ( b, encoding) )
217
228
. map ( BoxBody :: new) ;
0 commit comments