Skip to content

Commit 8b45af7

Browse files
authored
feat(server): add initial window builder methods that take self by-val (#1817)
The current `Builder` methods `http2_initial_stream_window_size` and `http2_initial_connection_window_size` take `&mut self`, while every other builder method takes `self`. That breaks up the chaining of options. This patch adds two methods that configure the same option, but take `self` instead, and have an underscore suffix (so, `http2_initial_stream_window_size_`). cc #1814
1 parent 2d9f349 commit 8b45af7

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

benches/end_to_end.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,11 @@ fn spawn_hello(rt: &mut Runtime, opts: &Opts) -> SocketAddr {
235235
let addr = "127.0.0.1:0".parse().unwrap();
236236

237237
let body = opts.response_body;
238-
let mut builder = Server::bind(&addr)
238+
let srv = Server::bind(&addr)
239239
.http2_only(opts.http2);
240-
// api woopsie
241-
builder
242-
.http2_initial_stream_window_size(opts.http2_stream_window)
243-
.http2_initial_connection_window_size(opts.http2_conn_window);
244-
245-
let srv = builder.serve(move || {
240+
.http2_initial_stream_window_size_(opts.http2_stream_window)
241+
.http2_initial_connection_window_size_(opts.http2_conn_window)
242+
.serve(move || {
246243
service_fn(move |req: Request<Body>| {
247244
req
248245
.into_body()

src/server/mod.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,21 +302,37 @@ impl<I, E> Builder<I, E> {
302302
self
303303
}
304304

305+
// soft-deprecated? deprecation warning just seems annoying...
306+
// reimplemented to take `self` instead of `&mut self`
307+
#[doc(hidden)]
308+
pub fn http2_initial_stream_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
309+
self.protocol.http2_initial_stream_window_size(sz.into());
310+
self
311+
}
312+
313+
// soft-deprecated? deprecation warning just seems annoying...
314+
// reimplemented to take `self` instead of `&mut self`
315+
#[doc(hidden)]
316+
pub fn http2_initial_connection_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
317+
self.protocol.http2_initial_connection_window_size(sz.into());
318+
self
319+
}
320+
305321
/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
306322
/// stream-level flow control.
307323
///
308324
/// Default is 65,535
309325
///
310326
/// [spec]: https://http2.github.io/http2-spec/#SETTINGS_INITIAL_WINDOW_SIZE
311-
pub fn http2_initial_stream_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
327+
pub fn http2_initial_stream_window_size_(mut self, sz: impl Into<Option<u32>>) -> Self {
312328
self.protocol.http2_initial_stream_window_size(sz.into());
313329
self
314330
}
315331

316332
/// Sets the max connection-level flow control for HTTP2
317333
///
318334
/// Default is 65,535
319-
pub fn http2_initial_connection_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
335+
pub fn http2_initial_connection_window_size_(mut self, sz: impl Into<Option<u32>>) -> Self {
320336
self.protocol.http2_initial_connection_window_size(sz.into());
321337
self
322338
}

0 commit comments

Comments
 (0)