volo_http/context/
server.rs1use volo::{
4 context::{Context, Reusable, Role, RpcCx, RpcInfo},
5 net::Address,
6 newtype_impl_context,
7};
8
9use crate::{
10 server::param::PathParamsVec,
11 utils::macros::{impl_deref_and_deref_mut, impl_getter},
12};
13
14#[derive(Debug)]
16pub struct ServerContext(pub(crate) RpcCx<ServerCxInner, Config>);
17
18impl ServerContext {
19 pub fn new(peer: Address) -> Self {
21 let mut cx = RpcCx::new(
22 RpcInfo::<Config>::with_role(Role::Server),
23 ServerCxInner::default(),
24 );
25 cx.rpc_info_mut().caller_mut().set_address(peer);
26 Self(cx)
27 }
28}
29
30impl_deref_and_deref_mut!(ServerContext, RpcCx<ServerCxInner, Config>, 0);
31
32newtype_impl_context!(ServerContext, Config, 0);
33
34#[derive(Clone, Debug, Default)]
36pub struct ServerCxInner {
37 pub params: PathParamsVec,
47}
48
49impl ServerCxInner {
50 impl_getter!(params, PathParamsVec);
51}
52
53#[derive(Clone, Debug, Default)]
57pub struct Config {
58 #[cfg(feature = "__tls")]
59 tls: bool,
60}
61
62impl Config {
63 #[cfg(feature = "__tls")]
65 pub fn is_tls(&self) -> bool {
66 self.tls
67 }
68
69 #[cfg(feature = "__tls")]
70 pub(crate) fn set_tls(&mut self, tls: bool) {
71 self.tls = tls;
72 }
73}
74
75impl Reusable for Config {
76 fn clear(&mut self) {
77 *self = Default::default();
78 }
79}