File tree Expand file tree Collapse file tree 1 file changed +26
-3
lines changed
tonic/src/transport/service Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,26 @@ impl<C> Connector<C> {
36
36
fn new ( inner : C , tls : Option < TlsConnector > ) -> Self {
37
37
Self { inner, tls }
38
38
}
39
+
40
+ #[ cfg( feature = "tls-roots" ) ]
41
+ fn tls_or_default ( & self , scheme : Option < & str > , host : Option < & str > ) -> Option < TlsConnector > {
42
+ use tokio_rustls:: webpki:: DNSNameRef ;
43
+
44
+ if self . tls . is_some ( ) {
45
+ return self . tls . clone ( ) ;
46
+ }
47
+
48
+ match ( scheme, host) {
49
+ ( Some ( "https" ) , Some ( host) ) => {
50
+ if DNSNameRef :: try_from_ascii ( host. as_bytes ( ) ) . is_ok ( ) {
51
+ TlsConnector :: new_with_rustls_cert ( None , None , host. to_owned ( ) ) . ok ( )
52
+ } else {
53
+ None
54
+ }
55
+ }
56
+ _ => None ,
57
+ }
58
+ }
39
59
}
40
60
41
61
impl < C > Service < Uri > for Connector < C >
@@ -54,11 +74,14 @@ where
54
74
}
55
75
56
76
fn call ( & mut self , uri : Uri ) -> Self :: Future {
57
- let connect = self . inner . make_connection ( uri) ;
58
-
59
- #[ cfg( feature = "tls" ) ]
77
+ #[ cfg( all( feature = "tls" , not( feature = "tls-roots" ) ) ) ]
60
78
let tls = self . tls . clone ( ) ;
61
79
80
+ #[ cfg( feature = "tls-roots" ) ]
81
+ let tls = self . tls_or_default ( uri. scheme_str ( ) , uri. host ( ) ) ;
82
+
83
+ let connect = self . inner . make_connection ( uri) ;
84
+
62
85
Box :: pin ( async move {
63
86
let io = connect. await ?;
64
87
You can’t perform that action at this time.
0 commit comments