hyperlane/context/struct.rs
1use crate::*;
2
3/// Represents the internal state of the application context.
4///
5/// This structure holds all the data associated with a single request-response cycle,
6/// including the stream, request, response, and any custom attributes.
7#[derive(Clone, Data, Default, CustomDebug, DisplayDebug)]
8pub(crate) struct ContextInner {
9 /// A flag indicating whether the request handling has been aborted.
10 #[get(pub(super))]
11 #[get_mut(pub(super))]
12 #[set(pub(super))]
13 aborted: bool,
14 /// A flag indicating whether the connection has been closed.
15 #[get(pub(super))]
16 #[get_mut(pub(super))]
17 #[set(pub(super))]
18 closed: bool,
19 /// The underlying network stream for the connection.
20 #[get(pub(super))]
21 #[get_mut(pub(super))]
22 #[set(pub(super))]
23 stream: OptionArcRwLockStream,
24 /// The incoming HTTP request.
25 #[get(pub(super))]
26 #[get_mut(pub(super))]
27 #[set(pub(super))]
28 request: Request,
29 /// The outgoing HTTP response.
30 #[get(pub(super))]
31 #[get_mut(pub(super))]
32 #[set(pub(super))]
33 response: Response,
34 /// Parameters extracted from the route path.
35 #[get(pub(super))]
36 #[get_mut(pub(super))]
37 #[set(pub(super))]
38 route_params: RouteParams,
39 /// A collection of custom attributes for sharing data within the request lifecycle.
40 #[get(pub(super))]
41 #[get_mut(pub(super))]
42 #[set(pub(super))]
43 attributes: HashMapArcAnySendSync,
44}
45
46/// The main application context, providing thread-safe access to request and response data.
47///
48/// This is a wrapper around `ContextInner` that uses an `Arc<RwLock<>>` to allow
49/// for shared, mutable access across asynchronous tasks.
50#[derive(Clone, Default, Getter, CustomDebug, DisplayDebug)]
51pub struct Context(#[get(pub(super))] pub(super) ArcRwLock<ContextInner>);