@@ -2,18 +2,21 @@ use std::time::Duration;
22
33use tonic:: service:: Interceptor ;
44
5- use crate :: { auth:: TokenInterceptor , Qdrant , QdrantError } ;
5+ use crate :: auth:: { TokenInterceptor , WrappedInterceptor } ;
6+ use crate :: qdrant_client:: GenericQdrant ;
7+ use crate :: QdrantError ;
68
7- struct DefaultConfigValues {
9+ struct DefaultConfigValues < I : Send + Sync + ' static + Clone + Interceptor = TokenInterceptor > {
810 timeout : Duration ,
911 connect_timeout : Duration ,
1012 keep_alive_while_idle : bool ,
1113 compression : Option < CompressionEncoding > ,
1214 check_compatibility : bool ,
1315 pool_size : usize ,
16+ interceptor : WrappedInterceptor < I > ,
1417}
1518
16- impl Default for DefaultConfigValues {
19+ impl < I : Send + Sync + ' static + Clone + Interceptor > Default for DefaultConfigValues < I > {
1720 fn default ( ) -> Self {
1821 Self {
1922 timeout : Duration :: from_secs ( 5 ) ,
@@ -22,6 +25,7 @@ impl Default for DefaultConfigValues {
2225 compression : None ,
2326 check_compatibility : true ,
2427 pool_size : 3 ,
28+ interceptor : WrappedInterceptor :: < I > :: default ( ) ,
2529 }
2630 }
2731}
@@ -65,11 +69,11 @@ pub struct QdrantConfig<I: Send + Sync + 'static + Clone + Interceptor = TokenIn
6569 pub pool_size : usize ,
6670
6771 /// The interceptor to use for modifying requests
68- pub interceptor : I ,
72+ pub interceptor : WrappedInterceptor < I > ,
6973}
7074
7175impl < I : Send + Sync + ' static + Clone + Interceptor > QdrantConfig < I > {
72- fn with_defaults ( url : & str , interceptor : I ) -> Self {
76+ fn with_defaults ( url : & str ) -> Self {
7377 let defaults = DefaultConfigValues :: default ( ) ;
7478 Self {
7579 uri : url. to_string ( ) ,
@@ -79,12 +83,20 @@ impl<I: Send + Sync + 'static + Clone + Interceptor> QdrantConfig<I> {
7983 compression : defaults. compression ,
8084 check_compatibility : defaults. check_compatibility ,
8185 pool_size : defaults. pool_size ,
82- interceptor,
86+ interceptor : defaults . interceptor ,
8387 }
8488 }
8589
86- pub fn from_url_with_interceptor ( url : & str , interceptor : I ) -> Self {
87- Self :: with_defaults ( url, interceptor)
90+ /// Start configuring a Qdrant client with an URL
91+ ///
92+ /// ```rust,no_run
93+ ///# use qdrant_client::config::QdrantConfig;
94+ /// let client = QdrantConfig::from_url("http://localhost:6334").build();
95+ /// ```
96+ ///
97+ /// This is normally done through [`Qdrant::from_url`](crate::Qdrant::from_url).
98+ pub fn from_url ( url : & str ) -> Self {
99+ Self :: with_defaults ( url)
88100 }
89101
90102 /// Keep the connection alive while idle
@@ -136,6 +148,33 @@ impl<I: Send + Sync + 'static + Clone + Interceptor> QdrantConfig<I> {
136148 self
137149 }
138150
151+ /// Set the interceptor to use for this client
152+ ///
153+ /// ```no_run
154+ /// use qdrant_client::GenericQdrant;
155+ /// use tonic::service::Interceptor;
156+ /// use tonic::{Request, Status};
157+ ///
158+ /// #[derive(Clone)]
159+ /// struct CustomInterceptor;
160+ /// impl Interceptor for CustomInterceptor {
161+ /// fn call(&mut self, req: Request<()>) -> Result<Request<()>, Status> {
162+ /// Ok(req)
163+ /// }
164+ /// }
165+ ///
166+ ///# async fn connect() -> Result<(), qdrant_client::QdrantError> {
167+ /// let client = GenericQdrant<CustomInterceptor>::from_url("http://localhost:6334")
168+ /// .interceptor(CustomInterceptor)
169+ /// .build()?;
170+ ///# Ok(())
171+ ///# }
172+ /// ```
173+ pub fn interceptor ( mut self , interceptor : I ) -> Self {
174+ self . interceptor = WrappedInterceptor :: new ( interceptor) ;
175+ self
176+ }
177+
139178 /// Set the timeout for this client
140179 ///
141180 /// Also see [`timeout()`](fn@Self::timeout).
@@ -164,9 +203,16 @@ impl<I: Send + Sync + 'static + Clone + Interceptor> QdrantConfig<I> {
164203 self . compression = compression;
165204 }
166205
206+ /// Set the interceptor to use for this client
207+ ///
208+ /// Also see [`interceptor()`](fn@Self::interceptor).
209+ pub fn set_interceptor ( & mut self , interceptor : I ) {
210+ self . interceptor = WrappedInterceptor :: new ( interceptor) ;
211+ }
212+
167213 /// Build the configured [`Qdrant`] client
168- pub fn build ( self ) -> Result < Qdrant < I > , QdrantError > {
169- Qdrant :: new ( self )
214+ pub fn build ( self ) -> Result < GenericQdrant < I > , QdrantError > {
215+ GenericQdrant :: new ( self )
170216 }
171217
172218 pub fn skip_compatibility_check ( mut self ) -> Self {
@@ -182,18 +228,6 @@ impl<I: Send + Sync + 'static + Clone + Interceptor> QdrantConfig<I> {
182228}
183229
184230impl QdrantConfig < TokenInterceptor > {
185- /// Start configuring a Qdrant client with an URL
186- ///
187- /// ```rust,no_run
188- ///# use qdrant_client::config::QdrantConfig;
189- /// let client = QdrantConfig::from_url("http://localhost:6334").build();
190- /// ```
191- ///
192- /// This is normally done through [`Qdrant::from_url`](crate::Qdrant::from_url).
193- pub fn from_url ( url : & str ) -> Self {
194- Self :: with_defaults ( url, TokenInterceptor :: new ( None ) )
195- }
196-
197231 /// Set an optional API key
198232 ///
199233 /// This method is only available when using the default TokenInterceptor.
@@ -209,15 +243,16 @@ impl QdrantConfig<TokenInterceptor> {
209243 /// .build();
210244 /// ```
211245 pub fn api_key ( mut self , api_key : impl AsOptionApiKey ) -> Self {
212- self . interceptor = TokenInterceptor :: new ( api_key. api_key ( ) ) ;
246+ self . interceptor = WrappedInterceptor :: new ( TokenInterceptor :: new ( api_key. api_key ( ) ) ) ;
213247 self
214248 }
215249
216250 /// Set an API key
217251 ///
218252 /// Also see [`api_key()`](fn@Self::api_key).
219253 pub fn set_api_key ( & mut self , api_key : & str ) {
220- self . interceptor = TokenInterceptor :: new ( Some ( api_key. to_string ( ) ) ) ;
254+ self . interceptor =
255+ WrappedInterceptor :: new ( TokenInterceptor :: new ( Some ( api_key. to_string ( ) ) ) ) ;
221256 }
222257}
223258
@@ -226,7 +261,7 @@ impl QdrantConfig<TokenInterceptor> {
226261/// Connects to `http://localhost:6334` without an API key.
227262impl Default for QdrantConfig < TokenInterceptor > {
228263 fn default ( ) -> Self {
229- Self :: with_defaults ( "http://localhost:6334" , TokenInterceptor :: new ( None ) )
264+ Self :: with_defaults ( "http://localhost:6334" )
230265 }
231266}
232267
0 commit comments