@@ -403,9 +403,10 @@ impl HttpBindingConfig {
403403/// not use the WebSocket extension protocol to connect with a runtime extension.
404404#[ derive( Clone , Copy , Debug ) ]
405405pub struct WsBindingConfig {
406- pub authenticated : bool ,
407- pub encrypted : bool ,
408- pub extension : bool ,
406+ authenticated : bool ,
407+ secure_subdomain : bool ,
408+ encrypted : bool ,
409+ extension : bool ,
409410}
410411
411412impl WsBindingConfig {
@@ -415,15 +416,22 @@ impl WsBindingConfig {
415416 pub fn default ( ) -> Self {
416417 Self {
417418 authenticated : true ,
419+ secure_subdomain : false ,
418420 encrypted : false ,
419421 extension : false ,
420422 }
421423 }
422424
423425 /// Create a new WsBindingConfig with the given values.
424- pub fn new ( authenticated : bool , encrypted : bool , extension : bool ) -> Self {
426+ pub fn new (
427+ authenticated : bool ,
428+ secure_subdomain : bool ,
429+ encrypted : bool ,
430+ extension : bool ,
431+ ) -> Self {
425432 Self {
426433 authenticated,
434+ secure_subdomain,
427435 encrypted,
428436 extension,
429437 }
@@ -435,6 +443,12 @@ impl WsBindingConfig {
435443 self
436444 }
437445
446+ /// Set whether the WebSocket server will be bound on a secure subdomain.
447+ pub fn secure_subdomain ( mut self , secure_subdomain : bool ) -> Self {
448+ self . secure_subdomain = secure_subdomain;
449+ self
450+ }
451+
438452 /// Set whether the WebSocket server will apply a custom encryption to the WebSocket
439453 /// connection using the login cookie.
440454 pub fn encrypted ( mut self , encrypted : bool ) -> Self {
@@ -516,22 +530,32 @@ impl HttpServer {
516530 {
517531 let path: String = path. into ( ) ;
518532 let res = KiRequest :: to ( ( "our" , "http_server" , "distro" , "sys" ) )
519- . body (
533+ . body ( if config. secure_subdomain {
534+ serde_json:: to_vec ( & HttpServerAction :: WebSocketSecureBind {
535+ path : path. clone ( ) ,
536+ encrypted : config. encrypted ,
537+ extension : config. extension ,
538+ } )
539+ . unwrap ( )
540+ } else {
520541 serde_json:: to_vec ( & HttpServerAction :: WebSocketBind {
521542 path : path. clone ( ) ,
522543 authenticated : config. authenticated ,
523544 encrypted : config. encrypted ,
524545 extension : config. extension ,
525546 } )
526- . unwrap ( ) ,
527- )
547+ . unwrap ( )
548+ } )
528549 . send_and_await_response ( self . timeout ) ;
529550 let Ok ( Message :: Response { body, .. } ) = res. unwrap ( ) else {
530551 return Err ( HttpServerError :: Timeout ) ;
531552 } ;
532553 let Ok ( resp) = serde_json:: from_slice :: < Result < ( ) , HttpServerError > > ( & body) else {
533554 return Err ( HttpServerError :: UnexpectedResponse ) ;
534555 } ;
556+ if resp. is_ok ( ) {
557+ self . ws_paths . insert ( path, config) ;
558+ }
535559 resp
536560 }
537561
@@ -644,9 +668,8 @@ impl HttpServer {
644668 let path: String = path. into ( ) ;
645669 let res = KiRequest :: to ( ( "our" , "http_server" , "distro" , "sys" ) )
646670 . body (
647- serde_json:: to_vec ( & HttpServerAction :: WebSocketBind {
671+ serde_json:: to_vec ( & HttpServerAction :: WebSocketSecureBind {
648672 path : path. clone ( ) ,
649- authenticated : true ,
650673 encrypted : false ,
651674 extension : false ,
652675 } )
@@ -664,6 +687,7 @@ impl HttpServer {
664687 path,
665688 WsBindingConfig {
666689 authenticated : true ,
690+ secure_subdomain : true ,
667691 encrypted : false ,
668692 extension : false ,
669693 } ,
@@ -727,15 +751,22 @@ impl HttpServer {
727751 error : "path not found" . to_string ( ) ,
728752 } ) ?;
729753 let res = KiRequest :: to ( ( "our" , "http_server" , "distro" , "sys" ) )
730- . body (
754+ . body ( if entry. secure_subdomain {
755+ serde_json:: to_vec ( & HttpServerAction :: WebSocketSecureBind {
756+ path : path. to_string ( ) ,
757+ encrypted : config. encrypted ,
758+ extension : config. extension ,
759+ } )
760+ . unwrap ( )
761+ } else {
731762 serde_json:: to_vec ( & HttpServerAction :: WebSocketBind {
732763 path : path. to_string ( ) ,
733764 authenticated : config. authenticated ,
734765 encrypted : config. encrypted ,
735766 extension : config. extension ,
736767 } )
737- . unwrap ( ) ,
738- )
768+ . unwrap ( )
769+ } )
739770 . send_and_await_response ( self . timeout )
740771 . unwrap ( ) ;
741772 let Ok ( Message :: Response { body, .. } ) = res else {
@@ -746,6 +777,7 @@ impl HttpServer {
746777 } ;
747778 if resp. is_ok ( ) {
748779 entry. authenticated = config. authenticated ;
780+ entry. secure_subdomain = config. secure_subdomain ;
749781 entry. encrypted = config. encrypted ;
750782 entry. extension = config. extension ;
751783 }
0 commit comments