@@ -167,14 +167,40 @@ impl Endpoint {
167167
168168struct EndpointInner {
169169 svcs : HashMap < String , BoxedService > ,
170- discovery : crate :: discovery:: Endpoint ,
170+ discovery_services : Vec < crate :: discovery:: Service > ,
171171 identity_verifier : IdentityVerifier ,
172172}
173173
174+ #[ derive( Default ) ]
175+ pub ( crate ) enum ProtocolMode {
176+ #[ allow( dead_code) ]
177+ RequestResponse ,
178+ #[ default]
179+ BidiStream ,
180+ }
181+
182+ /// Options for [`Endpoint::handle`].
183+ #[ derive( Default ) ]
184+ pub ( crate ) struct HandleOptions {
185+ pub ( crate ) protocol_mode : ProtocolMode ,
186+ }
187+
174188impl Endpoint {
189+ /// Handle an [`http::Request`], producing an [`http::Response`].
175190 pub fn handle < B : Body < Data = Bytes , Error : Into < BoxError > + Send > + Send + ' static > (
176191 & self ,
177192 req : http:: Request < B > ,
193+ ) -> Result < http:: Response < ResponseBody > , Error > {
194+ self . handle_with_options ( req, HandleOptions :: default ( ) )
195+ }
196+
197+ /// Handle an [`http::Request`], producing an [`http::Response`].
198+ pub ( crate ) fn handle_with_options <
199+ B : Body < Data = Bytes , Error : Into < BoxError > + Send > + Send + ' static ,
200+ > (
201+ & self ,
202+ req : http:: Request < B > ,
203+ options : HandleOptions ,
178204 ) -> Result < http:: Response < ResponseBody > , Error > {
179205 let ( parts, body) = req. into_parts ( ) ;
180206 let path = parts. uri . path ( ) ;
@@ -190,7 +216,7 @@ impl Endpoint {
190216 return self . handle_health ( ) ;
191217 }
192218 if parts. last ( ) == Some ( & "discover" ) {
193- return self . handle_discovery ( headers) ;
219+ return self . handle_discovery ( headers, options . protocol_mode ) ;
194220 }
195221
196222 // Parse service name/handler name
@@ -262,6 +288,7 @@ impl Endpoint {
262288 fn handle_discovery (
263289 & self ,
264290 headers : http:: HeaderMap ,
291+ protocol_mode : ProtocolMode ,
265292 ) -> Result < http:: Response < ResponseBody > , Error > {
266293 // Extract Accept header from request
267294 let accept_header = match headers
@@ -300,7 +327,18 @@ impl Endpoint {
300327 value: content_type. into( ) ,
301328 } ] ,
302329 Bytes :: from (
303- serde_json:: to_string ( & self . 0 . discovery ) . expect ( "Discovery should be serializable" ) ,
330+ serde_json:: to_string ( & crate :: discovery:: Endpoint {
331+ max_protocol_version : 5 ,
332+ min_protocol_version : 5 ,
333+ protocol_mode : Some ( match protocol_mode {
334+ ProtocolMode :: RequestResponse => {
335+ crate :: discovery:: ProtocolMode :: RequestResponse
336+ }
337+ ProtocolMode :: BidiStream => crate :: discovery:: ProtocolMode :: BidiStream ,
338+ } ) ,
339+ services : self . 0 . discovery_services . clone ( ) ,
340+ } )
341+ . expect ( "Discovery should be serializable" ) ,
304342 ) ,
305343 ) )
306344 }
@@ -309,7 +347,7 @@ impl Endpoint {
309347 // Validate that new discovery fields aren't used with older protocol versions
310348 if version <= 2 {
311349 // Check for new discovery fields in version 3 that shouldn't be used in version 2 or lower
312- for service in & self . 0 . discovery . services {
350+ for service in & self . 0 . discovery_services {
313351 if service. inactivity_timeout . is_some ( ) {
314352 Err ( ErrorInner :: FieldRequiresMinimumVersion (
315353 "inactivity_timeout" ,
0 commit comments