spring_grpc/
config.rs

1use schemars::JsonSchema;
2use serde::Deserialize;
3use spring::config::Configurable;
4use std::{
5    net::{IpAddr, Ipv4Addr},
6    time::Duration,
7};
8
9/// spring-grpc Config
10#[derive(Debug, Configurable, JsonSchema, Deserialize)]
11#[config_prefix = "grpc"]
12pub struct GrpcConfig {
13    #[serde(default = "default_binding")]
14    pub(crate) binding: IpAddr,
15    #[serde(default = "default_port")]
16    pub(crate) port: u16,
17
18    /// Set the concurrency limit applied to on requests inbound per connection.
19    pub(crate) concurrency_limit_per_connection: Option<usize>,
20
21    /// Set a timeout on for all request handlers.
22    pub(crate) timeout: Option<Duration>,
23
24    /// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
25    /// stream-level flow control.
26    ///
27    /// Default is 65,535
28    ///
29    /// [spec]: https://httpwg.org/specs/rfc9113.html#InitialWindowSize
30    pub(crate) initial_stream_window_size: Option<u32>,
31
32    /// Sets the max connection-level flow control for HTTP2
33    pub(crate) initial_connection_window_size: Option<u32>,
34
35    /// Sets the [`SETTINGS_MAX_CONCURRENT_STREAMS`][spec] option for HTTP2
36    /// connections.
37    pub(crate) max_concurrent_streams: Option<u32>,
38
39    /// Sets the maximum time option in milliseconds that a connection may exist
40    ///
41    /// Default is no limit (`None`).
42    pub(crate) max_connection_age: Option<Duration>,
43
44    /// Set whether HTTP2 Ping frames are enabled on accepted connections.
45    ///
46    /// If `None` is specified, HTTP2 keepalive is disabled, otherwise the duration
47    /// specified will be the time interval between HTTP2 Ping frames.
48    /// The timeout for receiving an acknowledgement of the keepalive ping
49    /// can be set with [`Server::http2_keepalive_timeout`].
50    ///
51    /// Default is no HTTP2 keepalive (`None`)
52    pub(crate) http2_keepalive_interval: Option<Duration>,
53
54    /// Sets a timeout for receiving an acknowledgement of the keepalive ping.
55    ///
56    /// If the ping is not acknowledged within the timeout, the connection will be closed.
57    /// Does nothing if http2_keep_alive_interval is disabled.
58    ///
59    /// Default is 20 seconds.
60    pub(crate) http2_keepalive_timeout: Option<Duration>,
61
62    /// Sets whether to use an adaptive flow control. Defaults to false.
63    /// Enabling this will override the limits set in http2_initial_stream_window_size and
64    /// http2_initial_connection_window_size.
65    pub(crate) http2_adaptive_window: Option<bool>,
66
67    /// Configures the maximum number of pending reset streams allowed before a GOAWAY will be sent.
68    ///
69    /// This will default to whatever the default in h2 is. As of v0.3.17, it is 20.
70    ///
71    /// See <https://github.com/hyperium/hyper/issues/2877> for more information.
72    pub(crate) http2_max_pending_accept_reset_streams: Option<usize>,
73
74    /// Set whether TCP keepalive messages are enabled on accepted connections.
75    ///
76    /// If `None` is specified, keepalive is disabled, otherwise the duration
77    /// specified will be the time to remain idle before sending TCP keepalive
78    /// probes.
79    ///
80    /// Default is no keepalive (`None`)
81    pub(crate) tcp_keepalive: Option<Duration>,
82
83    /// Set the value of `TCP_NODELAY` option for accepted connections. Enabled by default.
84    #[serde(default)]
85    pub(crate) tcp_nodelay: bool,
86
87    /// Sets the max size of received header frames.
88    ///
89    /// This will default to whatever the default in hyper is. As of v1.4.1, it is 16 KiB.
90    pub(crate) http2_max_header_list_size: Option<u32>,
91
92    /// Sets the maximum frame size to use for HTTP2.
93    ///
94    /// Passing `None` will do nothing.
95    ///
96    /// If not set, will default from underlying transport.
97    pub(crate) max_frame_size: Option<u32>,
98
99    /// Allow this server to accept http1 requests.
100    ///
101    /// Accepting http1 requests is only useful when developing `grpc-web`
102    /// enabled services. If this setting is set to `true` but services are
103    /// not correctly configured to handle grpc-web requests, your server may
104    /// return confusing (but correct) protocol errors.
105    ///
106    /// Default is `false`.
107    #[serde(default)]
108    pub(crate) accept_http1: bool,
109
110    #[serde(default)]
111    pub(crate) graceful: bool,
112}
113
114fn default_binding() -> IpAddr {
115    IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0))
116}
117
118fn default_port() -> u16 {
119    9090
120}