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