@@ -30,6 +30,7 @@ use std::fmt;
30
30
/// [gRPC protocol definition]: https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests
31
31
pub struct Grpc < T > {
32
32
inner : T ,
33
+ origin : Uri ,
33
34
/// Which compression encodings does the client accept?
34
35
accept_compression_encodings : EnabledCompressionEncodings ,
35
36
/// The compression encoding that will be applied to requests.
@@ -41,6 +42,20 @@ impl<T> Grpc<T> {
41
42
pub fn new ( inner : T ) -> Self {
42
43
Self {
43
44
inner,
45
+ origin : Uri :: default ( ) ,
46
+ send_compression_encodings : None ,
47
+ accept_compression_encodings : EnabledCompressionEncodings :: default ( ) ,
48
+ }
49
+ }
50
+
51
+ /// Creates a new gRPC client with the provided [`GrpcService`] and `Uri`.
52
+ ///
53
+ /// The provided Uri will use only the scheme and authority parts as the
54
+ /// path_and_query portion will be set for each method.
55
+ pub fn with_origin ( inner : T , origin : Uri ) -> Self {
56
+ Self {
57
+ inner,
58
+ origin,
44
59
send_compression_encodings : None ,
45
60
accept_compression_encodings : EnabledCompressionEncodings :: default ( ) ,
46
61
}
@@ -211,8 +226,13 @@ impl<T> Grpc<T> {
211
226
M1 : Send + Sync + ' static ,
212
227
M2 : Send + Sync + ' static ,
213
228
{
229
+ let scheme = self . origin . scheme ( ) . cloned ( ) ;
230
+ let authority = self . origin . authority ( ) . cloned ( ) ;
231
+
214
232
let mut parts = Parts :: default ( ) ;
215
233
parts. path_and_query = Some ( path) ;
234
+ parts. scheme = scheme;
235
+ parts. authority = authority;
216
236
217
237
let uri = Uri :: from_parts ( parts) . expect ( "path_and_query only is valid Uri" ) ;
218
238
@@ -296,6 +316,7 @@ impl<T: Clone> Clone for Grpc<T> {
296
316
fn clone ( & self ) -> Self {
297
317
Self {
298
318
inner : self . inner . clone ( ) ,
319
+ origin : self . origin . clone ( ) ,
299
320
send_compression_encodings : self . send_compression_encodings ,
300
321
accept_compression_encodings : self . accept_compression_encodings ,
301
322
}
@@ -308,6 +329,8 @@ impl<T: fmt::Debug> fmt::Debug for Grpc<T> {
308
329
309
330
f. field ( "inner" , & self . inner ) ;
310
331
332
+ f. field ( "origin" , & self . origin ) ;
333
+
311
334
f. field ( "compression_encoding" , & self . send_compression_encodings ) ;
312
335
313
336
f. field (
0 commit comments