Skip to content

Commit 11bff07

Browse files
committed
Multiple HTTP Bindings function added
1 parent dc01f89 commit 11bff07

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/http/server.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,48 @@ impl HttpServer {
10481048
pub fn get_ws_channels(&self) -> HashMap<String, HashSet<u32>> {
10491049
self.ws_channels.clone()
10501050
}
1051+
1052+
/// Register multiple paths with the HTTP server using the same configuration.
1053+
/// Uses the security setting from HttpBindingConfig if secure is None,
1054+
/// forces secure binding if Some(true), or forces non-secure binding if Some(false).
1055+
/// All paths must be bound successfully, or none will be bound. If any path
1056+
/// fails to bind, all previously bound paths will be unbound before returning
1057+
/// the error.
1058+
pub fn bind_multiple_http_paths<T: Into<String>>(
1059+
&mut self,
1060+
paths: Vec<T>,
1061+
config: HttpBindingConfig,
1062+
secure: Option<bool>,
1063+
) -> Result<(), HttpServerError> {
1064+
let mut bound_paths = Vec::new();
1065+
1066+
for path in paths {
1067+
let path_str = path.into();
1068+
let result = match secure {
1069+
Some(true) => self.secure_bind_http_path(path_str.clone()),
1070+
Some(false) => self.bind_http_path(path_str.clone(), config.clone()),
1071+
None => {
1072+
if config.secure_subdomain {
1073+
self.secure_bind_http_path(path_str.clone())
1074+
} else {
1075+
self.bind_http_path(path_str.clone(), config.clone())
1076+
}
1077+
}
1078+
};
1079+
match result {
1080+
Ok(_) => bound_paths.push(path_str),
1081+
Err(e) => {
1082+
// If binding fails, unbind all previously bound paths
1083+
for bound_path in bound_paths {
1084+
let _ = self.unbind_http_path(&bound_path);
1085+
}
1086+
return Err(e);
1087+
}
1088+
}
1089+
}
1090+
1091+
Ok(())
1092+
}
10511093
}
10521094

10531095
/// Send an HTTP response to an incoming HTTP request ([`HttpServerRequest::Http`]).

0 commit comments

Comments
 (0)