@@ -30,6 +30,7 @@ use std::fmt;
3030/// [gRPC protocol definition]: https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests
3131pub struct Grpc < T > {
3232 inner : T ,
33+ origin : Uri ,
3334 /// Which compression encodings does the client accept?
3435 accept_compression_encodings : EnabledCompressionEncodings ,
3536 /// The compression encoding that will be applied to requests.
@@ -41,6 +42,20 @@ impl<T> Grpc<T> {
4142 pub fn new ( inner : T ) -> Self {
4243 Self {
4344 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,
4459 send_compression_encodings : None ,
4560 accept_compression_encodings : EnabledCompressionEncodings :: default ( ) ,
4661 }
@@ -211,8 +226,13 @@ impl<T> Grpc<T> {
211226 M1 : Send + Sync + ' static ,
212227 M2 : Send + Sync + ' static ,
213228 {
229+ let scheme = self . origin . scheme ( ) . cloned ( ) ;
230+ let authority = self . origin . authority ( ) . cloned ( ) ;
231+
214232 let mut parts = Parts :: default ( ) ;
215233 parts. path_and_query = Some ( path) ;
234+ parts. scheme = scheme;
235+ parts. authority = authority;
216236
217237 let uri = Uri :: from_parts ( parts) . expect ( "path_and_query only is valid Uri" ) ;
218238
@@ -296,6 +316,7 @@ impl<T: Clone> Clone for Grpc<T> {
296316 fn clone ( & self ) -> Self {
297317 Self {
298318 inner : self . inner . clone ( ) ,
319+ origin : self . origin . clone ( ) ,
299320 send_compression_encodings : self . send_compression_encodings ,
300321 accept_compression_encodings : self . accept_compression_encodings ,
301322 }
@@ -308,6 +329,8 @@ impl<T: fmt::Debug> fmt::Debug for Grpc<T> {
308329
309330 f. field ( "inner" , & self . inner ) ;
310331
332+ f. field ( "origin" , & self . origin ) ;
333+
311334 f. field ( "compression_encoding" , & self . send_compression_encodings ) ;
312335
313336 f. field (
0 commit comments