hyperlane/server/struct.rs
1use crate::*;
2
3/// Represents the state associated with a single connection hook.
4///
5/// This struct encapsulates the necessary context for processing a connection,
6/// including a reference to the network stream and request configuration. It is created
7/// for each connection and passed to the relevant handlers.
8#[derive(Clone, CustomDebug, DisplayDebug, Getter, New)]
9pub(crate) struct HandlerState {
10 /// A reference to the underlying network stream for the connection.
11 pub(super) stream: ArcRwLockStream,
12 /// The server for the current connection.
13 pub(super) server: &'static Server,
14}
15
16/// Represents the internal, mutable state of the web server.
17///
18/// This struct consolidates all the core components required for the server to operate,
19/// including configuration, routing, middleware, and various hooks for extending functionality.
20#[derive(Clone, CustomDebug, Data, DisplayDebug, New)]
21pub struct Server {
22 /// Stores the server's configuration settings, such as address, port, and timeouts.
23 #[get_mut(skip)]
24 #[set(pub(super))]
25 pub(super) server_config: ServerConfig,
26 /// The configuration for HTTP request.
27 #[get_mut(skip)]
28 #[set(pub(super))]
29 pub(super) request_config: RequestConfig,
30 /// The routing component responsible for matching incoming requests to their registered handlers.
31 #[get_mut(pub(super))]
32 #[set(skip)]
33 pub(super) route_matcher: RouteMatcher,
34 /// A collection of request error handlers that are invoked when a request error occurs during HTTP request processing.
35 /// This allows for graceful error recovery and customized error responses.
36 #[debug(skip)]
37 #[get_mut(pub(super))]
38 #[set(skip)]
39 pub(super) request_error: ServerHookList,
40 /// A collection of task panic handlers that are invoked when a panic occurs during request processing.
41 /// This allows for graceful error recovery and customized error responses.
42 #[debug(skip)]
43 #[get_mut(pub(super))]
44 #[set(skip)]
45 pub(super) task_panic: ServerHookList,
46 /// A collection of request middleware handlers.
47 #[debug(skip)]
48 #[get_mut(pub(super))]
49 #[set(skip)]
50 pub(super) request_middleware: ServerHookList,
51 /// A collection of response middleware handlers.
52 #[debug(skip)]
53 #[get_mut(pub(super))]
54 #[set(skip)]
55 pub(super) response_middleware: ServerHookList,
56}