Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-frmr committed Dec 9, 2024
2 parents c09923a + 746a1f5 commit 65d4bc3
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/http/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,41 @@ impl HttpServer {
pub fn get_ws_channels(&self) -> HashMap<String, HashSet<u32>> {
self.ws_channels.clone()
}

/// Register multiple paths with the HTTP server using the same configuration.
/// The security setting is determined by the `secure_subdomain` field in `HttpBindingConfig`.
/// All paths must be bound successfully, or none will be bound. If any path
/// fails to bind, all previously bound paths will be unbound before returning
/// the error.
pub fn bind_multiple_http_paths<T: Into<String>>(
&mut self,
paths: Vec<T>,
config: HttpBindingConfig,
) -> Result<(), HttpServerError> {
let mut bound_paths = Vec::new();

for path in paths {
let path_str = path.into();
let result = match config.secure_subdomain {
true => self.secure_bind_http_path(path_str.clone()),
false => self.bind_http_path(path_str.clone(), config.clone()),
};

match result {
// If binding succeeds, add the path to the list of bound paths
Ok(_) => bound_paths.push(path_str),
// If binding fails, unbind all previously bound paths
Err(e) => {
for bound_path in bound_paths {
let _ = self.unbind_http_path(&bound_path);
}
return Err(e);
}
}
}

Ok(())
}
}

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

0 comments on commit 65d4bc3

Please sign in to comment.