wreq-rb 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Cargo.lock +2688 -0
- data/Cargo.toml +6 -0
- data/README.md +179 -0
- data/ext/wreq_rb/Cargo.toml +39 -0
- data/ext/wreq_rb/extconf.rb +22 -0
- data/ext/wreq_rb/src/client.rs +565 -0
- data/ext/wreq_rb/src/error.rs +25 -0
- data/ext/wreq_rb/src/lib.rs +20 -0
- data/ext/wreq_rb/src/response.rs +132 -0
- data/lib/wreq-rb/version.rb +5 -0
- data/lib/wreq-rb.rb +17 -0
- data/patches/0001-add-transfer-size-tracking.patch +292 -0
- data/vendor/wreq/Cargo.toml +306 -0
- data/vendor/wreq/LICENSE +202 -0
- data/vendor/wreq/README.md +122 -0
- data/vendor/wreq/examples/cert_store.rs +77 -0
- data/vendor/wreq/examples/connect_via_lower_priority_tokio_runtime.rs +258 -0
- data/vendor/wreq/examples/emulation.rs +118 -0
- data/vendor/wreq/examples/form.rs +14 -0
- data/vendor/wreq/examples/http1_websocket.rs +37 -0
- data/vendor/wreq/examples/http2_websocket.rs +45 -0
- data/vendor/wreq/examples/json_dynamic.rs +41 -0
- data/vendor/wreq/examples/json_typed.rs +47 -0
- data/vendor/wreq/examples/keylog.rs +16 -0
- data/vendor/wreq/examples/request_with_emulation.rs +115 -0
- data/vendor/wreq/examples/request_with_interface.rs +37 -0
- data/vendor/wreq/examples/request_with_local_address.rs +16 -0
- data/vendor/wreq/examples/request_with_proxy.rs +13 -0
- data/vendor/wreq/examples/request_with_redirect.rs +22 -0
- data/vendor/wreq/examples/request_with_version.rs +15 -0
- data/vendor/wreq/examples/tor_socks.rs +24 -0
- data/vendor/wreq/examples/unix_socket.rs +33 -0
- data/vendor/wreq/src/client/body.rs +304 -0
- data/vendor/wreq/src/client/conn/conn.rs +231 -0
- data/vendor/wreq/src/client/conn/connector.rs +549 -0
- data/vendor/wreq/src/client/conn/http.rs +1023 -0
- data/vendor/wreq/src/client/conn/proxy/socks.rs +233 -0
- data/vendor/wreq/src/client/conn/proxy/tunnel.rs +260 -0
- data/vendor/wreq/src/client/conn/proxy.rs +39 -0
- data/vendor/wreq/src/client/conn/tls_info.rs +98 -0
- data/vendor/wreq/src/client/conn/uds.rs +44 -0
- data/vendor/wreq/src/client/conn/verbose.rs +149 -0
- data/vendor/wreq/src/client/conn.rs +323 -0
- data/vendor/wreq/src/client/core/body/incoming.rs +485 -0
- data/vendor/wreq/src/client/core/body/length.rs +118 -0
- data/vendor/wreq/src/client/core/body.rs +34 -0
- data/vendor/wreq/src/client/core/common/buf.rs +149 -0
- data/vendor/wreq/src/client/core/common/rewind.rs +141 -0
- data/vendor/wreq/src/client/core/common/watch.rs +76 -0
- data/vendor/wreq/src/client/core/common.rs +3 -0
- data/vendor/wreq/src/client/core/conn/http1.rs +342 -0
- data/vendor/wreq/src/client/core/conn/http2.rs +307 -0
- data/vendor/wreq/src/client/core/conn.rs +11 -0
- data/vendor/wreq/src/client/core/dispatch.rs +299 -0
- data/vendor/wreq/src/client/core/error.rs +435 -0
- data/vendor/wreq/src/client/core/ext.rs +201 -0
- data/vendor/wreq/src/client/core/http1.rs +178 -0
- data/vendor/wreq/src/client/core/http2.rs +483 -0
- data/vendor/wreq/src/client/core/proto/h1/conn.rs +988 -0
- data/vendor/wreq/src/client/core/proto/h1/decode.rs +1170 -0
- data/vendor/wreq/src/client/core/proto/h1/dispatch.rs +684 -0
- data/vendor/wreq/src/client/core/proto/h1/encode.rs +580 -0
- data/vendor/wreq/src/client/core/proto/h1/io.rs +879 -0
- data/vendor/wreq/src/client/core/proto/h1/role.rs +694 -0
- data/vendor/wreq/src/client/core/proto/h1.rs +104 -0
- data/vendor/wreq/src/client/core/proto/h2/client.rs +650 -0
- data/vendor/wreq/src/client/core/proto/h2/ping.rs +539 -0
- data/vendor/wreq/src/client/core/proto/h2.rs +379 -0
- data/vendor/wreq/src/client/core/proto/headers.rs +138 -0
- data/vendor/wreq/src/client/core/proto.rs +58 -0
- data/vendor/wreq/src/client/core/rt/bounds.rs +57 -0
- data/vendor/wreq/src/client/core/rt/timer.rs +150 -0
- data/vendor/wreq/src/client/core/rt/tokio.rs +99 -0
- data/vendor/wreq/src/client/core/rt.rs +25 -0
- data/vendor/wreq/src/client/core/upgrade.rs +267 -0
- data/vendor/wreq/src/client/core.rs +16 -0
- data/vendor/wreq/src/client/emulation.rs +161 -0
- data/vendor/wreq/src/client/http/client/error.rs +142 -0
- data/vendor/wreq/src/client/http/client/exec.rs +29 -0
- data/vendor/wreq/src/client/http/client/extra.rs +77 -0
- data/vendor/wreq/src/client/http/client/lazy.rs +79 -0
- data/vendor/wreq/src/client/http/client/pool.rs +1105 -0
- data/vendor/wreq/src/client/http/client/util.rs +104 -0
- data/vendor/wreq/src/client/http/client.rs +1003 -0
- data/vendor/wreq/src/client/http/future.rs +99 -0
- data/vendor/wreq/src/client/http.rs +1629 -0
- data/vendor/wreq/src/client/layer/config/options.rs +156 -0
- data/vendor/wreq/src/client/layer/config.rs +116 -0
- data/vendor/wreq/src/client/layer/cookie.rs +161 -0
- data/vendor/wreq/src/client/layer/decoder.rs +139 -0
- data/vendor/wreq/src/client/layer/redirect/future.rs +270 -0
- data/vendor/wreq/src/client/layer/redirect/policy.rs +63 -0
- data/vendor/wreq/src/client/layer/redirect.rs +145 -0
- data/vendor/wreq/src/client/layer/retry/classify.rs +105 -0
- data/vendor/wreq/src/client/layer/retry/scope.rs +51 -0
- data/vendor/wreq/src/client/layer/retry.rs +151 -0
- data/vendor/wreq/src/client/layer/timeout/body.rs +233 -0
- data/vendor/wreq/src/client/layer/timeout/future.rs +90 -0
- data/vendor/wreq/src/client/layer/timeout.rs +177 -0
- data/vendor/wreq/src/client/layer.rs +15 -0
- data/vendor/wreq/src/client/multipart.rs +717 -0
- data/vendor/wreq/src/client/request.rs +818 -0
- data/vendor/wreq/src/client/response.rs +534 -0
- data/vendor/wreq/src/client/ws/json.rs +99 -0
- data/vendor/wreq/src/client/ws/message.rs +453 -0
- data/vendor/wreq/src/client/ws.rs +714 -0
- data/vendor/wreq/src/client.rs +27 -0
- data/vendor/wreq/src/config.rs +140 -0
- data/vendor/wreq/src/cookie.rs +579 -0
- data/vendor/wreq/src/dns/gai.rs +249 -0
- data/vendor/wreq/src/dns/hickory.rs +78 -0
- data/vendor/wreq/src/dns/resolve.rs +180 -0
- data/vendor/wreq/src/dns.rs +69 -0
- data/vendor/wreq/src/error.rs +502 -0
- data/vendor/wreq/src/ext.rs +398 -0
- data/vendor/wreq/src/hash.rs +143 -0
- data/vendor/wreq/src/header.rs +506 -0
- data/vendor/wreq/src/into_uri.rs +187 -0
- data/vendor/wreq/src/lib.rs +586 -0
- data/vendor/wreq/src/proxy/mac.rs +82 -0
- data/vendor/wreq/src/proxy/matcher.rs +806 -0
- data/vendor/wreq/src/proxy/uds.rs +66 -0
- data/vendor/wreq/src/proxy/win.rs +31 -0
- data/vendor/wreq/src/proxy.rs +569 -0
- data/vendor/wreq/src/redirect.rs +575 -0
- data/vendor/wreq/src/retry.rs +198 -0
- data/vendor/wreq/src/sync.rs +129 -0
- data/vendor/wreq/src/tls/conn/cache.rs +123 -0
- data/vendor/wreq/src/tls/conn/cert_compression.rs +125 -0
- data/vendor/wreq/src/tls/conn/ext.rs +82 -0
- data/vendor/wreq/src/tls/conn/macros.rs +34 -0
- data/vendor/wreq/src/tls/conn/service.rs +138 -0
- data/vendor/wreq/src/tls/conn.rs +681 -0
- data/vendor/wreq/src/tls/keylog/handle.rs +64 -0
- data/vendor/wreq/src/tls/keylog.rs +99 -0
- data/vendor/wreq/src/tls/options.rs +464 -0
- data/vendor/wreq/src/tls/x509/identity.rs +122 -0
- data/vendor/wreq/src/tls/x509/parser.rs +71 -0
- data/vendor/wreq/src/tls/x509/store.rs +228 -0
- data/vendor/wreq/src/tls/x509.rs +68 -0
- data/vendor/wreq/src/tls.rs +154 -0
- data/vendor/wreq/src/trace.rs +55 -0
- data/vendor/wreq/src/util.rs +122 -0
- data/vendor/wreq/tests/badssl.rs +228 -0
- data/vendor/wreq/tests/brotli.rs +350 -0
- data/vendor/wreq/tests/client.rs +1098 -0
- data/vendor/wreq/tests/connector_layers.rs +227 -0
- data/vendor/wreq/tests/cookie.rs +306 -0
- data/vendor/wreq/tests/deflate.rs +347 -0
- data/vendor/wreq/tests/emulation.rs +260 -0
- data/vendor/wreq/tests/gzip.rs +347 -0
- data/vendor/wreq/tests/layers.rs +261 -0
- data/vendor/wreq/tests/multipart.rs +165 -0
- data/vendor/wreq/tests/proxy.rs +438 -0
- data/vendor/wreq/tests/redirect.rs +629 -0
- data/vendor/wreq/tests/retry.rs +135 -0
- data/vendor/wreq/tests/support/delay_server.rs +117 -0
- data/vendor/wreq/tests/support/error.rs +16 -0
- data/vendor/wreq/tests/support/layer.rs +183 -0
- data/vendor/wreq/tests/support/mod.rs +9 -0
- data/vendor/wreq/tests/support/server.rs +232 -0
- data/vendor/wreq/tests/timeouts.rs +281 -0
- data/vendor/wreq/tests/unix_socket.rs +135 -0
- data/vendor/wreq/tests/upgrade.rs +98 -0
- data/vendor/wreq/tests/zstd.rs +559 -0
- metadata +225 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
//! HTTP/1 connection configuration.
|
|
2
|
+
|
|
3
|
+
/// Builder for `Http1Options`.
|
|
4
|
+
#[must_use]
|
|
5
|
+
#[derive(Debug)]
|
|
6
|
+
pub struct Http1OptionsBuilder {
|
|
7
|
+
opts: Http1Options,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/// HTTP/1 protocol options for customizing connection behavior.
|
|
11
|
+
///
|
|
12
|
+
/// These options allow you to customize the behavior of HTTP/1 connections,
|
|
13
|
+
/// such as enabling support for HTTP/0.9 responses, header case preservation, etc.
|
|
14
|
+
#[derive(Debug, Default, Clone, Hash, PartialEq, Eq)]
|
|
15
|
+
#[non_exhaustive]
|
|
16
|
+
pub struct Http1Options {
|
|
17
|
+
/// Enable support for HTTP/0.9 responses.
|
|
18
|
+
pub h09_responses: bool,
|
|
19
|
+
|
|
20
|
+
/// Whether to use vectored writes for HTTP/1 connections.
|
|
21
|
+
pub h1_writev: Option<bool>,
|
|
22
|
+
|
|
23
|
+
/// Maximum number of headers allowed in HTTP/1 responses.
|
|
24
|
+
pub h1_max_headers: Option<usize>,
|
|
25
|
+
|
|
26
|
+
/// Exact size of the read buffer to use for HTTP/1 connections.
|
|
27
|
+
pub h1_read_buf_exact_size: Option<usize>,
|
|
28
|
+
|
|
29
|
+
/// Maximum buffer size for HTTP/1 connections.
|
|
30
|
+
pub h1_max_buf_size: Option<usize>,
|
|
31
|
+
|
|
32
|
+
/// Whether to ignore invalid headers in HTTP/1 responses.
|
|
33
|
+
pub ignore_invalid_headers_in_responses: bool,
|
|
34
|
+
|
|
35
|
+
/// Whether to allow spaces after header names in HTTP/1 responses.
|
|
36
|
+
pub allow_spaces_after_header_name_in_responses: bool,
|
|
37
|
+
|
|
38
|
+
/// Whether to allow obsolete multiline headers in HTTP/1 responses.
|
|
39
|
+
pub allow_obsolete_multiline_headers_in_responses: bool,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
impl Http1OptionsBuilder {
|
|
43
|
+
/// Set the `http09_responses` field.
|
|
44
|
+
#[inline]
|
|
45
|
+
pub fn http09_responses(mut self, enabled: bool) -> Self {
|
|
46
|
+
self.opts.h09_responses = enabled;
|
|
47
|
+
self
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/// Set whether HTTP/1 connections should try to use vectored writes,
|
|
51
|
+
/// or always flatten into a single buffer.
|
|
52
|
+
///
|
|
53
|
+
/// Note that setting this to false may mean more copies of body data,
|
|
54
|
+
/// but may also improve performance when an IO transport doesn't
|
|
55
|
+
/// support vectored writes well, such as most TLS implementations.
|
|
56
|
+
///
|
|
57
|
+
/// Setting this to true will force crate::core: to use queued strategy
|
|
58
|
+
/// which may eliminate unnecessary cloning on some TLS backends
|
|
59
|
+
///
|
|
60
|
+
/// Default is `auto`. In this mode crate::core: will try to guess which
|
|
61
|
+
/// mode to use
|
|
62
|
+
#[inline]
|
|
63
|
+
pub fn writev(mut self, writev: Option<bool>) -> Self {
|
|
64
|
+
self.opts.h1_writev = writev;
|
|
65
|
+
self
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/// Set the maximum number of headers.
|
|
69
|
+
///
|
|
70
|
+
/// When a response is received, the parser will reserve a buffer to store headers for optimal
|
|
71
|
+
/// performance.
|
|
72
|
+
///
|
|
73
|
+
/// If client receives more headers than the buffer size, the error "message header too large"
|
|
74
|
+
/// is returned.
|
|
75
|
+
///
|
|
76
|
+
/// Note that headers is allocated on the stack by default, which has higher performance. After
|
|
77
|
+
/// setting this value, headers will be allocated in heap memory, that is, heap memory
|
|
78
|
+
/// allocation will occur for each response, and there will be a performance drop of about 5%.
|
|
79
|
+
///
|
|
80
|
+
/// Default is 100.
|
|
81
|
+
#[inline]
|
|
82
|
+
pub fn max_headers(mut self, max_headers: usize) -> Self {
|
|
83
|
+
self.opts.h1_max_headers = Some(max_headers);
|
|
84
|
+
self
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/// Sets the exact size of the read buffer to *always* use.
|
|
88
|
+
///
|
|
89
|
+
/// Note that setting this option unsets the `max_buf_size` option.
|
|
90
|
+
///
|
|
91
|
+
/// Default is an adaptive read buffer.
|
|
92
|
+
#[inline]
|
|
93
|
+
pub fn read_buf_exact_size(mut self, sz: Option<usize>) -> Self {
|
|
94
|
+
self.opts.h1_read_buf_exact_size = sz;
|
|
95
|
+
self.opts.h1_max_buf_size = None;
|
|
96
|
+
self
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/// Set the maximum buffer size for the connection.
|
|
100
|
+
///
|
|
101
|
+
/// Default is ~400kb.
|
|
102
|
+
///
|
|
103
|
+
/// Note that setting this option unsets the `read_exact_buf_size` option.
|
|
104
|
+
///
|
|
105
|
+
/// # Panics
|
|
106
|
+
///
|
|
107
|
+
/// The minimum value allowed is 8192. This method panics if the passed `max` is less than the
|
|
108
|
+
/// minimum.
|
|
109
|
+
#[inline]
|
|
110
|
+
pub fn max_buf_size(mut self, max: usize) -> Self {
|
|
111
|
+
assert!(
|
|
112
|
+
max >= super::proto::h1::MINIMUM_MAX_BUFFER_SIZE,
|
|
113
|
+
"the max_buf_size cannot be smaller than the minimum that h1 specifies."
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
self.opts.h1_max_buf_size = Some(max);
|
|
117
|
+
self.opts.h1_read_buf_exact_size = None;
|
|
118
|
+
self
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/// Set whether HTTP/1 connections will accept spaces between header names
|
|
122
|
+
/// and the colon that follow them in responses.
|
|
123
|
+
///
|
|
124
|
+
/// You probably don't need this, here is what [RFC 7230 Section 3.2.4.] has
|
|
125
|
+
/// to say about it:
|
|
126
|
+
///
|
|
127
|
+
/// > No whitespace is allowed between the header field-name and colon. In
|
|
128
|
+
/// > the past, differences in the handling of such whitespace have led to
|
|
129
|
+
/// > security vulnerabilities in request routing and response handling. A
|
|
130
|
+
/// > server MUST reject any received request message that contains
|
|
131
|
+
/// > whitespace between a header field-name and colon with a response code
|
|
132
|
+
/// > of 400 (Bad Request). A proxy MUST remove any such whitespace from a
|
|
133
|
+
/// > response message before forwarding the message downstream.
|
|
134
|
+
///
|
|
135
|
+
/// Default is false.
|
|
136
|
+
///
|
|
137
|
+
/// [RFC 7230 Section 3.2.4.]: https://tools.ietf.org/html/rfc7230#section-3.2.4
|
|
138
|
+
#[inline]
|
|
139
|
+
pub fn allow_spaces_after_header_name_in_responses(mut self, enabled: bool) -> Self {
|
|
140
|
+
self.opts.allow_spaces_after_header_name_in_responses = enabled;
|
|
141
|
+
self
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/// Set whether HTTP/1 connections will silently ignored malformed header lines.
|
|
145
|
+
///
|
|
146
|
+
/// If this is enabled and a header line does not start with a valid header
|
|
147
|
+
/// name, or does not include a colon at all, the line will be silently ignored
|
|
148
|
+
/// and no error will be reported.
|
|
149
|
+
///
|
|
150
|
+
/// Default is false.
|
|
151
|
+
#[inline]
|
|
152
|
+
pub fn ignore_invalid_headers_in_responses(mut self, enabled: bool) -> Self {
|
|
153
|
+
self.opts.ignore_invalid_headers_in_responses = enabled;
|
|
154
|
+
self
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/// Set the `allow_obsolete_multiline_headers_in_responses` field.
|
|
158
|
+
#[inline]
|
|
159
|
+
pub fn allow_obsolete_multiline_headers_in_responses(mut self, value: bool) -> Self {
|
|
160
|
+
self.opts.allow_obsolete_multiline_headers_in_responses = value;
|
|
161
|
+
self
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/// Build the [`Http1Options`] instance.
|
|
165
|
+
#[inline]
|
|
166
|
+
pub fn build(self) -> Http1Options {
|
|
167
|
+
self.opts
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
impl Http1Options {
|
|
172
|
+
/// Create a new [`Http1OptionsBuilder`].
|
|
173
|
+
pub fn builder() -> Http1OptionsBuilder {
|
|
174
|
+
Http1OptionsBuilder {
|
|
175
|
+
opts: Http1Options::default(),
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
//! HTTP/2 connection configuration.
|
|
2
|
+
|
|
3
|
+
use std::time::Duration;
|
|
4
|
+
|
|
5
|
+
pub use http2::frame::{
|
|
6
|
+
ExperimentalSettings, Priorities, PrioritiesBuilder, Priority, PseudoId, PseudoOrder, Setting,
|
|
7
|
+
SettingId, SettingsOrder, SettingsOrderBuilder, StreamDependency, StreamId,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
use super::proto;
|
|
11
|
+
|
|
12
|
+
// Our defaults are chosen for the "majority" case, which usually are not
|
|
13
|
+
// resource constrained, and so the spec default of 64kb can be too limiting
|
|
14
|
+
// for performance.
|
|
15
|
+
const DEFAULT_CONN_WINDOW_SIZE: u32 = 1024 * 1024 * 5; // 5mb
|
|
16
|
+
const DEFAULT_WINDOW_SIZE: u32 = 1024 * 1024 * 2; // 2mb
|
|
17
|
+
const DEFAULT_MAX_SEND_BUF_SIZE: usize = 1024 * 1024; // 1mb
|
|
18
|
+
|
|
19
|
+
// The maximum number of concurrent streams that the client is allowed to open
|
|
20
|
+
// before it receives the initial SETTINGS frame from the server.
|
|
21
|
+
// This default value is derived from what the HTTP/2 spec recommends as the
|
|
22
|
+
// minimum value that endpoints advertise to their peers. It means that using
|
|
23
|
+
// this value will minimize the chance of the failure where the local endpoint
|
|
24
|
+
// attempts to open too many streams and gets rejected by the remote peer with
|
|
25
|
+
// the `REFUSED_STREAM` error.
|
|
26
|
+
const DEFAULT_INITIAL_MAX_SEND_STREAMS: usize = 100;
|
|
27
|
+
|
|
28
|
+
/// Builder for `Http2Options`.
|
|
29
|
+
#[must_use]
|
|
30
|
+
#[derive(Debug)]
|
|
31
|
+
pub struct Http2OptionsBuilder {
|
|
32
|
+
opts: Http2Options,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/// Configuration for an HTTP/2 connection.
|
|
36
|
+
///
|
|
37
|
+
/// This struct defines various parameters to fine-tune the behavior of an HTTP/2 connection,
|
|
38
|
+
/// including stream management, window sizes, frame limits, and header config.
|
|
39
|
+
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
|
|
40
|
+
#[non_exhaustive]
|
|
41
|
+
pub struct Http2Options {
|
|
42
|
+
/// Whether to use adaptive flow control.
|
|
43
|
+
pub adaptive_window: bool,
|
|
44
|
+
|
|
45
|
+
/// The initial stream ID for the connection.
|
|
46
|
+
pub initial_stream_id: Option<u32>,
|
|
47
|
+
|
|
48
|
+
/// The initial window size for HTTP/2 connection-level flow control.
|
|
49
|
+
pub initial_conn_window_size: u32,
|
|
50
|
+
|
|
51
|
+
/// The initial window size for HTTP/2 streams.
|
|
52
|
+
pub initial_window_size: u32,
|
|
53
|
+
|
|
54
|
+
/// The initial maximum number of locally initiated (send) streams.
|
|
55
|
+
pub initial_max_send_streams: usize,
|
|
56
|
+
|
|
57
|
+
/// The maximum frame size to use for HTTP/2.
|
|
58
|
+
pub max_frame_size: Option<u32>,
|
|
59
|
+
|
|
60
|
+
/// The interval for HTTP/2 keep-alive ping frames.
|
|
61
|
+
pub keep_alive_interval: Option<Duration>,
|
|
62
|
+
|
|
63
|
+
/// The timeout for receiving an acknowledgement of the keep-alive ping.
|
|
64
|
+
pub keep_alive_timeout: Duration,
|
|
65
|
+
|
|
66
|
+
/// Whether HTTP/2 keep-alive should apply while the connection is idle.
|
|
67
|
+
pub keep_alive_while_idle: bool,
|
|
68
|
+
|
|
69
|
+
/// The maximum number of concurrent locally reset streams.
|
|
70
|
+
pub max_concurrent_reset_streams: Option<usize>,
|
|
71
|
+
|
|
72
|
+
/// The maximum size of the send buffer for HTTP/2 streams.
|
|
73
|
+
pub max_send_buffer_size: usize,
|
|
74
|
+
|
|
75
|
+
/// The maximum number of concurrent streams initiated by the remote peer.
|
|
76
|
+
pub max_concurrent_streams: Option<u32>,
|
|
77
|
+
|
|
78
|
+
/// The maximum size of the header list.
|
|
79
|
+
pub max_header_list_size: Option<u32>,
|
|
80
|
+
|
|
81
|
+
/// The maximum number of pending accept reset streams.
|
|
82
|
+
pub max_pending_accept_reset_streams: Option<usize>,
|
|
83
|
+
|
|
84
|
+
/// Whether to enable push promises.
|
|
85
|
+
pub enable_push: Option<bool>,
|
|
86
|
+
|
|
87
|
+
/// The header table size for HPACK compression.
|
|
88
|
+
pub header_table_size: Option<u32>,
|
|
89
|
+
|
|
90
|
+
/// Whether to enable the CONNECT protocol.
|
|
91
|
+
pub enable_connect_protocol: Option<bool>,
|
|
92
|
+
|
|
93
|
+
/// Whether to disable RFC 7540 Stream Priorities.
|
|
94
|
+
pub no_rfc7540_priorities: Option<bool>,
|
|
95
|
+
|
|
96
|
+
/// The HTTP/2 pseudo-header field order for outgoing HEADERS frames.
|
|
97
|
+
pub headers_pseudo_order: Option<PseudoOrder>,
|
|
98
|
+
|
|
99
|
+
/// The stream dependency for the outgoing HEADERS frame.
|
|
100
|
+
pub headers_stream_dependency: Option<StreamDependency>,
|
|
101
|
+
|
|
102
|
+
/// Custom experimental HTTP/2 settings.
|
|
103
|
+
pub experimental_settings: Option<ExperimentalSettings>,
|
|
104
|
+
|
|
105
|
+
/// The order of settings parameters in the initial SETTINGS frame.
|
|
106
|
+
pub settings_order: Option<SettingsOrder>,
|
|
107
|
+
|
|
108
|
+
/// The list of PRIORITY frames to be sent after connection establishment.
|
|
109
|
+
pub priorities: Option<Priorities>,
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
impl Http2OptionsBuilder {
|
|
113
|
+
/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
|
|
114
|
+
/// stream-level flow control.
|
|
115
|
+
///
|
|
116
|
+
/// Passing `None` will do nothing.
|
|
117
|
+
///
|
|
118
|
+
/// If not set, crate::core: will use a default.
|
|
119
|
+
///
|
|
120
|
+
/// [spec]: https://httpwg.org/specs/rfc9113.html#SETTINGS_INITIAL_WINDOW_SIZE
|
|
121
|
+
#[inline]
|
|
122
|
+
pub fn initial_window_size(mut self, sz: impl Into<Option<u32>>) -> Self {
|
|
123
|
+
if let Some(sz) = sz.into() {
|
|
124
|
+
self.opts.adaptive_window = false;
|
|
125
|
+
self.opts.initial_window_size = sz;
|
|
126
|
+
}
|
|
127
|
+
self
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/// Sets the max connection-level flow control for HTTP2
|
|
131
|
+
///
|
|
132
|
+
/// Passing `None` will do nothing.
|
|
133
|
+
///
|
|
134
|
+
/// If not set, crate::core: will use a default.
|
|
135
|
+
#[inline]
|
|
136
|
+
pub fn initial_connection_window_size(mut self, sz: impl Into<Option<u32>>) -> Self {
|
|
137
|
+
if let Some(sz) = sz.into() {
|
|
138
|
+
self.opts.adaptive_window = false;
|
|
139
|
+
self.opts.initial_conn_window_size = sz;
|
|
140
|
+
}
|
|
141
|
+
self
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/// Sets the initial maximum of locally initiated (send) streams.
|
|
145
|
+
///
|
|
146
|
+
/// This value will be overwritten by the value included in the initial
|
|
147
|
+
/// SETTINGS frame received from the peer as part of a [connection preface].
|
|
148
|
+
///
|
|
149
|
+
/// Passing `None` will do nothing.
|
|
150
|
+
///
|
|
151
|
+
/// If not set, crate::core: will use a default.
|
|
152
|
+
///
|
|
153
|
+
/// [connection preface]: https://httpwg.org/specs/rfc9113.html#preface
|
|
154
|
+
#[inline]
|
|
155
|
+
pub fn initial_max_send_streams(mut self, initial: impl Into<Option<usize>>) -> Self {
|
|
156
|
+
if let Some(initial) = initial.into() {
|
|
157
|
+
self.opts.initial_max_send_streams = initial;
|
|
158
|
+
}
|
|
159
|
+
self
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/// Sets the initial stream id for the connection.
|
|
163
|
+
#[inline]
|
|
164
|
+
pub fn initial_stream_id(mut self, id: impl Into<Option<u32>>) -> Self {
|
|
165
|
+
if let Some(id) = id.into() {
|
|
166
|
+
self.opts.initial_stream_id = Some(id);
|
|
167
|
+
}
|
|
168
|
+
self
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/// Sets whether to use an adaptive flow control.
|
|
172
|
+
///
|
|
173
|
+
/// Enabling this will override the limits set in
|
|
174
|
+
/// `initial_stream_window_size` and
|
|
175
|
+
/// `initial_connection_window_size`.
|
|
176
|
+
#[inline]
|
|
177
|
+
pub fn adaptive_window(mut self, enabled: bool) -> Self {
|
|
178
|
+
use proto::h2::SPEC_WINDOW_SIZE;
|
|
179
|
+
|
|
180
|
+
self.opts.adaptive_window = enabled;
|
|
181
|
+
if enabled {
|
|
182
|
+
self.opts.initial_window_size = SPEC_WINDOW_SIZE;
|
|
183
|
+
self.opts.initial_conn_window_size = SPEC_WINDOW_SIZE;
|
|
184
|
+
}
|
|
185
|
+
self
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/// Sets the maximum frame size to use for HTTP2.
|
|
189
|
+
///
|
|
190
|
+
/// Default is currently 16KB, but can change.
|
|
191
|
+
#[inline]
|
|
192
|
+
pub fn max_frame_size(mut self, sz: impl Into<Option<u32>>) -> Self {
|
|
193
|
+
if let Some(sz) = sz.into() {
|
|
194
|
+
self.opts.max_frame_size = Some(sz);
|
|
195
|
+
}
|
|
196
|
+
self
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/// Sets the max size of received header frames.
|
|
200
|
+
///
|
|
201
|
+
/// Default is currently 16KB, but can change.
|
|
202
|
+
#[inline]
|
|
203
|
+
pub fn max_header_list_size(mut self, max: u32) -> Self {
|
|
204
|
+
self.opts.max_header_list_size = Some(max);
|
|
205
|
+
self
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/// Sets the header table size.
|
|
209
|
+
///
|
|
210
|
+
/// This setting informs the peer of the maximum size of the header compression
|
|
211
|
+
/// table used to encode header blocks, in octets. The encoder may select any value
|
|
212
|
+
/// equal to or less than the header table size specified by the sender.
|
|
213
|
+
///
|
|
214
|
+
/// The default value of crate `h2` is 4,096.
|
|
215
|
+
#[inline]
|
|
216
|
+
pub fn header_table_size(mut self, size: impl Into<Option<u32>>) -> Self {
|
|
217
|
+
if let Some(size) = size.into() {
|
|
218
|
+
self.opts.header_table_size = Some(size);
|
|
219
|
+
}
|
|
220
|
+
self
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/// Sets the maximum number of concurrent streams.
|
|
224
|
+
///
|
|
225
|
+
/// The maximum concurrent streams setting only controls the maximum number
|
|
226
|
+
/// of streams that can be initiated by the remote peer. In other words,
|
|
227
|
+
/// when this setting is set to 100, this does not limit the number of
|
|
228
|
+
/// concurrent streams that can be created by the caller.
|
|
229
|
+
///
|
|
230
|
+
/// It is recommended that this value be no smaller than 100, so as to not
|
|
231
|
+
/// unnecessarily limit parallelism. However, any value is legal, including
|
|
232
|
+
/// 0. If `max` is set to 0, then the remote will not be permitted to
|
|
233
|
+
/// initiate streams.
|
|
234
|
+
///
|
|
235
|
+
/// Note that streams in the reserved state, i.e., push promises that have
|
|
236
|
+
/// been reserved but the stream has not started, do not count against this
|
|
237
|
+
/// setting.
|
|
238
|
+
///
|
|
239
|
+
/// Also note that if the remote *does* exceed the value set here, it is not
|
|
240
|
+
/// a protocol level error. Instead, the `h2` library will immediately reset
|
|
241
|
+
/// the stream.
|
|
242
|
+
///
|
|
243
|
+
/// See [Section 5.1.2] in the HTTP/2 spec for more details.
|
|
244
|
+
///
|
|
245
|
+
/// [Section 5.1.2]: https://http2.github.io/http2-spec/#rfc.section.5.1.2
|
|
246
|
+
#[inline]
|
|
247
|
+
pub fn max_concurrent_streams(mut self, max: impl Into<Option<u32>>) -> Self {
|
|
248
|
+
if let Some(max) = max.into() {
|
|
249
|
+
self.opts.max_concurrent_streams = Some(max);
|
|
250
|
+
}
|
|
251
|
+
self
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/// Sets an interval for HTTP2 Ping frames should be sent to keep a
|
|
255
|
+
/// connection alive.
|
|
256
|
+
///
|
|
257
|
+
/// Pass `None` to disable HTTP2 keep-alive.
|
|
258
|
+
///
|
|
259
|
+
/// Default is currently disabled.
|
|
260
|
+
#[inline]
|
|
261
|
+
pub fn keep_alive_interval(mut self, interval: impl Into<Option<Duration>>) -> Self {
|
|
262
|
+
self.opts.keep_alive_interval = interval.into();
|
|
263
|
+
self
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/// Sets a timeout for receiving an acknowledgement of the keep-alive ping.
|
|
267
|
+
///
|
|
268
|
+
/// If the ping is not acknowledged within the timeout, the connection will
|
|
269
|
+
/// be closed. Does nothing if `keep_alive_interval` is disabled.
|
|
270
|
+
///
|
|
271
|
+
/// Default is 20 seconds.
|
|
272
|
+
#[inline]
|
|
273
|
+
pub fn keep_alive_timeout(mut self, timeout: Duration) -> Self {
|
|
274
|
+
self.opts.keep_alive_timeout = timeout;
|
|
275
|
+
self
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/// Sets whether HTTP2 keep-alive should apply while the connection is idle.
|
|
279
|
+
///
|
|
280
|
+
/// If disabled, keep-alive pings are only sent while there are open
|
|
281
|
+
/// request/responses streams. If enabled, pings are also sent when no
|
|
282
|
+
/// streams are active. Does nothing if `keep_alive_interval` is
|
|
283
|
+
/// disabled.
|
|
284
|
+
///
|
|
285
|
+
/// Default is `false`.
|
|
286
|
+
#[inline]
|
|
287
|
+
pub fn keep_alive_while_idle(mut self, enabled: bool) -> Self {
|
|
288
|
+
self.opts.keep_alive_while_idle = enabled;
|
|
289
|
+
self
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/// Enables and disables the push feature for HTTP2.
|
|
293
|
+
///
|
|
294
|
+
/// Passing `None` will do nothing.
|
|
295
|
+
#[inline]
|
|
296
|
+
pub fn enable_push(mut self, opt: bool) -> Self {
|
|
297
|
+
self.opts.enable_push = Some(opt);
|
|
298
|
+
self
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/// Sets the enable connect protocol.
|
|
302
|
+
#[inline]
|
|
303
|
+
pub fn enable_connect_protocol(mut self, opt: bool) -> Self {
|
|
304
|
+
self.opts.enable_connect_protocol = Some(opt);
|
|
305
|
+
self
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/// Disable RFC 7540 Stream Priorities (set to `true` to disable).
|
|
309
|
+
/// [RFC 9218]: <https://www.rfc-editor.org/rfc/rfc9218.html#section-2.1>
|
|
310
|
+
#[inline]
|
|
311
|
+
pub fn no_rfc7540_priorities(mut self, opt: bool) -> Self {
|
|
312
|
+
self.opts.no_rfc7540_priorities = Some(opt);
|
|
313
|
+
self
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/// Sets the maximum number of HTTP2 concurrent locally reset streams.
|
|
317
|
+
///
|
|
318
|
+
/// See the documentation of [`http2::client::Builder::max_concurrent_reset_streams`] for more
|
|
319
|
+
/// details.
|
|
320
|
+
///
|
|
321
|
+
/// The default value is determined by the `h2` crate.
|
|
322
|
+
///
|
|
323
|
+
/// [`http2::client::Builder::max_concurrent_reset_streams`]: https://docs.rs/h2/client/struct.Builder.html#method.max_concurrent_reset_streams
|
|
324
|
+
#[inline]
|
|
325
|
+
pub fn max_concurrent_reset_streams(mut self, max: usize) -> Self {
|
|
326
|
+
self.opts.max_concurrent_reset_streams = Some(max);
|
|
327
|
+
self
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/// Set the maximum write buffer size for each HTTP/2 stream.
|
|
331
|
+
///
|
|
332
|
+
/// Default is currently 1MB, but may change.
|
|
333
|
+
///
|
|
334
|
+
/// # Panics
|
|
335
|
+
///
|
|
336
|
+
/// The value must be no larger than `u32::MAX`.
|
|
337
|
+
#[inline]
|
|
338
|
+
pub fn max_send_buf_size(mut self, max: usize) -> Self {
|
|
339
|
+
assert!(max <= u32::MAX as usize);
|
|
340
|
+
self.opts.max_send_buffer_size = max;
|
|
341
|
+
self
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/// Configures the maximum number of pending reset streams allowed before a GOAWAY will be sent.
|
|
345
|
+
///
|
|
346
|
+
/// See <https://github.com/hyperium/hyper/issues/2877> for more information.
|
|
347
|
+
#[inline]
|
|
348
|
+
pub fn max_pending_accept_reset_streams(mut self, max: impl Into<Option<usize>>) -> Self {
|
|
349
|
+
if let Some(max) = max.into() {
|
|
350
|
+
self.opts.max_pending_accept_reset_streams = Some(max);
|
|
351
|
+
}
|
|
352
|
+
self
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/// Sets the stream dependency and weight for the outgoing HEADERS frame.
|
|
356
|
+
///
|
|
357
|
+
/// This configures the priority of the stream by specifying its dependency and weight,
|
|
358
|
+
/// as defined by the HTTP/2 priority mechanism. This can be used to influence how the
|
|
359
|
+
/// server allocates resources to this stream relative to others.
|
|
360
|
+
#[inline]
|
|
361
|
+
pub fn headers_stream_dependency<T>(mut self, stream_dependency: T) -> Self
|
|
362
|
+
where
|
|
363
|
+
T: Into<Option<StreamDependency>>,
|
|
364
|
+
{
|
|
365
|
+
if let Some(stream_dependency) = stream_dependency.into() {
|
|
366
|
+
self.opts.headers_stream_dependency = Some(stream_dependency);
|
|
367
|
+
}
|
|
368
|
+
self
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/// Sets the HTTP/2 pseudo-header field order for outgoing HEADERS frames.
|
|
372
|
+
///
|
|
373
|
+
/// This determines the order in which pseudo-header fields (such as `:method`, `:scheme`, etc.)
|
|
374
|
+
/// are encoded in the HEADERS frame. Customizing the order may be useful for interoperability
|
|
375
|
+
/// or testing purposes.
|
|
376
|
+
#[inline]
|
|
377
|
+
pub fn headers_pseudo_order<T>(mut self, headers_pseudo_order: T) -> Self
|
|
378
|
+
where
|
|
379
|
+
T: Into<Option<PseudoOrder>>,
|
|
380
|
+
{
|
|
381
|
+
if let Some(headers_pseudo_order) = headers_pseudo_order.into() {
|
|
382
|
+
self.opts.headers_pseudo_order = Some(headers_pseudo_order);
|
|
383
|
+
}
|
|
384
|
+
self
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/// Configures custom experimental HTTP/2 setting.
|
|
388
|
+
///
|
|
389
|
+
/// This setting is reserved for future use or experimental purposes.
|
|
390
|
+
/// Enabling or disabling it may have no effect unless explicitly supported
|
|
391
|
+
/// by the server or client implementation.
|
|
392
|
+
#[inline]
|
|
393
|
+
pub fn experimental_settings<T>(mut self, experimental_settings: T) -> Self
|
|
394
|
+
where
|
|
395
|
+
T: Into<Option<ExperimentalSettings>>,
|
|
396
|
+
{
|
|
397
|
+
if let Some(experimental_settings) = experimental_settings.into() {
|
|
398
|
+
self.opts.experimental_settings = Some(experimental_settings);
|
|
399
|
+
}
|
|
400
|
+
self
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/// Sets the order of settings parameters in the initial SETTINGS frame.
|
|
404
|
+
///
|
|
405
|
+
/// This determines the order in which settings are sent during the HTTP/2 handshake.
|
|
406
|
+
/// Customizing the order may be useful for testing or protocol compliance.
|
|
407
|
+
#[inline]
|
|
408
|
+
pub fn settings_order<T>(mut self, settings_order: T) -> Self
|
|
409
|
+
where
|
|
410
|
+
T: Into<Option<SettingsOrder>>,
|
|
411
|
+
{
|
|
412
|
+
if let Some(settings_order) = settings_order.into() {
|
|
413
|
+
self.opts.settings_order = Some(settings_order);
|
|
414
|
+
}
|
|
415
|
+
self
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/// Sets the list of PRIORITY frames to be sent immediately after the connection is established,
|
|
419
|
+
/// but before the first request is sent.
|
|
420
|
+
///
|
|
421
|
+
/// This allows you to pre-configure the HTTP/2 stream dependency tree by specifying a set of
|
|
422
|
+
/// PRIORITY frames that will be sent as part of the connection preface. This can be useful for
|
|
423
|
+
/// optimizing resource allocation or testing custom stream prioritization strategies.
|
|
424
|
+
///
|
|
425
|
+
/// Each `Priority` in the list must have a valid (non-zero) stream ID. Any priority with a
|
|
426
|
+
/// stream ID of zero will be ignored.
|
|
427
|
+
#[inline]
|
|
428
|
+
pub fn priorities<T>(mut self, priorities: T) -> Self
|
|
429
|
+
where
|
|
430
|
+
T: Into<Option<Priorities>>,
|
|
431
|
+
{
|
|
432
|
+
if let Some(priorities) = priorities.into() {
|
|
433
|
+
self.opts.priorities = Some(priorities);
|
|
434
|
+
}
|
|
435
|
+
self
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/// Builds the `Http2Options` instance.
|
|
439
|
+
#[inline]
|
|
440
|
+
pub fn build(self) -> Http2Options {
|
|
441
|
+
self.opts
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
impl Http2Options {
|
|
446
|
+
/// Creates a new `Http2OptionsBuilder` instance.
|
|
447
|
+
pub fn builder() -> Http2OptionsBuilder {
|
|
448
|
+
Http2OptionsBuilder {
|
|
449
|
+
opts: Http2Options::default(),
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
impl Default for Http2Options {
|
|
455
|
+
#[inline]
|
|
456
|
+
fn default() -> Self {
|
|
457
|
+
Http2Options {
|
|
458
|
+
adaptive_window: false,
|
|
459
|
+
initial_stream_id: None,
|
|
460
|
+
initial_conn_window_size: DEFAULT_CONN_WINDOW_SIZE,
|
|
461
|
+
initial_window_size: DEFAULT_WINDOW_SIZE,
|
|
462
|
+
initial_max_send_streams: DEFAULT_INITIAL_MAX_SEND_STREAMS,
|
|
463
|
+
max_frame_size: None,
|
|
464
|
+
max_header_list_size: None,
|
|
465
|
+
keep_alive_interval: None,
|
|
466
|
+
keep_alive_timeout: Duration::from_secs(20),
|
|
467
|
+
keep_alive_while_idle: false,
|
|
468
|
+
max_concurrent_reset_streams: None,
|
|
469
|
+
max_send_buffer_size: DEFAULT_MAX_SEND_BUF_SIZE,
|
|
470
|
+
max_pending_accept_reset_streams: None,
|
|
471
|
+
header_table_size: None,
|
|
472
|
+
max_concurrent_streams: None,
|
|
473
|
+
enable_push: None,
|
|
474
|
+
enable_connect_protocol: None,
|
|
475
|
+
no_rfc7540_priorities: None,
|
|
476
|
+
experimental_settings: None,
|
|
477
|
+
settings_order: None,
|
|
478
|
+
headers_pseudo_order: None,
|
|
479
|
+
headers_stream_dependency: None,
|
|
480
|
+
priorities: None,
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|