1
- use std:: { collections :: HashMap , error:: Error , future:: Future , net:: SocketAddr , pin:: Pin } ;
1
+ use std:: { error:: Error , future:: Future , net:: SocketAddr , pin:: Pin } ;
2
2
3
3
use async_channel:: Sender ;
4
4
use async_trait:: async_trait;
@@ -394,86 +394,6 @@ impl ResponseDataBuilder {
394
394
}
395
395
}
396
396
397
- /// Represents the root configuration for the server.
398
- ///
399
- /// This struct encapsulates a mapping between configuration property names and their corresponding
400
- /// YAML values, allowing for organized access to server settings.
401
- pub struct ServerConfigRoot {
402
- hashmap : HashMap < String , ServerConfig > ,
403
- }
404
-
405
- impl ServerConfigRoot {
406
- /// Constructs a new `ServerConfigRoot` instance from a given YAML hash.
407
- ///
408
- /// This function takes a YAML object, expects it to be a hash (mapping), and converts it into
409
- /// a `HashMap` where each key is a `String` and each value is a `Yaml` object. This allows for
410
- /// easy retrieval of configuration properties by their names.
411
- ///
412
- /// # Parameters
413
- ///
414
- /// - `hashmap_yaml`: A reference to `ServerConfig` object expected to be a hash containing configuration properties.
415
- ///
416
- /// # Returns
417
- ///
418
- /// A `ServerConfigRoot` instance containing the parsed configuration properties.
419
- pub fn new ( hashmap_yaml : & ServerConfig ) -> Self {
420
- let mut hashmap = HashMap :: new ( ) ;
421
-
422
- if let Some ( hashmap_yaml) = hashmap_yaml. as_hash ( ) {
423
- for ( key, value) in hashmap_yaml. iter ( ) {
424
- if let Some ( key_str) = key. as_str ( ) {
425
- hashmap. insert ( key_str. to_string ( ) , value. clone ( ) ) ;
426
- }
427
- }
428
- }
429
-
430
- ServerConfigRoot { hashmap }
431
- }
432
-
433
- /// Constructs a new `ServerConfigRoot` instance from an existing `HashMap<String, ServerConfig>`.
434
- ///
435
- /// # Parameters
436
- ///
437
- /// - `hashmap`: A `HashMap<String, ServerConfig>` hashmap.
438
- ///
439
- /// # Returns
440
- ///
441
- /// A `ServerConfigRoot` instance containing the parsed configuration properties.
442
- pub fn from_hash ( hashmap : HashMap < String , ServerConfig > ) -> Self {
443
- ServerConfigRoot { hashmap }
444
- }
445
-
446
- /// Retrieves a configuration property by its name.
447
- ///
448
- /// This function looks up the provided property name in the internal hashmap and returns
449
- /// a clone of the corresponding `Yaml` value if found. If the property is not found, it
450
- /// returns `Yaml::BadValue`.
451
- ///
452
- /// # Parameters
453
- ///
454
- /// - `property`: A string slice representing the name of the configuration property to retrieve.
455
- ///
456
- /// # Returns
457
- ///
458
- /// A `ServerConfig` object corresponding to the requested property, or `ServerConfig::BadValue` if the property
459
- /// does not exist in the configuration.
460
- pub fn get ( & self , property : & str ) -> ServerConfig {
461
- match self . hashmap . get ( property) {
462
- Some ( yaml) => yaml. clone ( ) ,
463
- None => ServerConfig :: BadValue ,
464
- }
465
- }
466
-
467
- /// Provides a reference to an underlying hashmap.
468
- ///
469
- /// # Returns
470
- ///
471
- /// A reference to `HashMap<String, ServerConfig>` hashmap.
472
- pub fn as_hash ( & self ) -> & HashMap < String , ServerConfig > {
473
- & self . hashmap
474
- }
475
- }
476
-
477
397
/// Defines the interface for server module handlers, specifying how requests should be processed.
478
398
#[ async_trait]
479
399
pub trait ServerModuleHandlers {
@@ -492,7 +412,7 @@ pub trait ServerModuleHandlers {
492
412
async fn request_handler (
493
413
& mut self ,
494
414
request : RequestData ,
495
- config : & ServerConfigRoot ,
415
+ config : & ServerConfig ,
496
416
socket_data : & SocketData ,
497
417
error_logger : & ErrorLogger ,
498
418
) -> Result < ResponseData , Box < dyn Error + Send + Sync > > ;
@@ -512,7 +432,7 @@ pub trait ServerModuleHandlers {
512
432
async fn proxy_request_handler (
513
433
& mut self ,
514
434
request : RequestData ,
515
- config : & ServerConfigRoot ,
435
+ config : & ServerConfig ,
516
436
socket_data : & SocketData ,
517
437
error_logger : & ErrorLogger ,
518
438
) -> Result < ResponseData , Box < dyn Error + Send + Sync > > ;
@@ -572,7 +492,7 @@ pub trait ServerModuleHandlers {
572
492
& mut self ,
573
493
upgraded_request : HyperUpgraded ,
574
494
connect_address : & str ,
575
- config : & ServerConfigRoot ,
495
+ config : & ServerConfig ,
576
496
socket_data : & SocketData ,
577
497
error_logger : & ErrorLogger ,
578
498
) -> Result < ( ) , Box < dyn Error + Send + Sync > > ;
@@ -601,7 +521,7 @@ pub trait ServerModuleHandlers {
601
521
& mut self ,
602
522
websocket : HyperWebsocket ,
603
523
uri : & hyper:: Uri ,
604
- config : & ServerConfigRoot ,
524
+ config : & ServerConfig ,
605
525
socket_data : & SocketData ,
606
526
error_logger : & ErrorLogger ,
607
527
) -> Result < ( ) , Box < dyn Error + Send + Sync > > ;
@@ -616,11 +536,7 @@ pub trait ServerModuleHandlers {
616
536
/// # Returns
617
537
///
618
538
/// `true` if the module is a module supporting WebSocket requests, or `false` otherwise.
619
- fn does_websocket_requests (
620
- & mut self ,
621
- config : & ServerConfigRoot ,
622
- socket_data : & SocketData ,
623
- ) -> bool ;
539
+ fn does_websocket_requests ( & mut self , config : & ServerConfig , socket_data : & SocketData ) -> bool ;
624
540
}
625
541
626
542
/// Represents a server module that can provide handlers for processing requests.
0 commit comments