Skip to content

Commit 6803663

Browse files
authored
chore(core): format http1 and http2 options wrappers (#813)
1 parent a0e63c5 commit 6803663

11 files changed

Lines changed: 208 additions & 224 deletions

File tree

examples/emulation_firefox.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ async fn main() -> wreq::Result<()> {
172172
Http2Options::builder()
173173
.initial_stream_id(15)
174174
.header_table_size(65536)
175-
.initial_stream_window_size(131072)
175+
.initial_window_size(131072)
176176
.max_frame_size(16384)
177177
.initial_connection_window_size(12517377 + 65535)
178178
.headers_stream_dependency(StreamDependency::new(StreamId::from(13), 41, false))

examples/emulation_twitter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async fn main() -> wreq::Result<()> {
5353
// HTTP/2 options config
5454
let http2 = Http2Options::builder()
5555
.initial_stream_id(3)
56-
.initial_stream_window_size(16777216)
56+
.initial_window_size(16777216)
5757
.initial_connection_window_size(16711681 + 65535)
5858
.headers_pseudo_order(
5959
PseudoOrder::builder()

examples/keylog.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ async fn main() -> wreq::Result<()> {
1111
// Use the API you're already familiar with
1212
let resp = client.get("https://api.ip.sb/ip").send().await?;
1313
println!("{}", resp.text().await?);
14-
14+
1515
Ok(())
1616
}

examples/request_with_emulation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async fn main() -> wreq::Result<()> {
5353
// HTTP/2 options config
5454
let http2 = Http2Options::builder()
5555
.initial_stream_id(3)
56-
.initial_stream_window_size(16777216)
56+
.initial_window_size(16777216)
5757
.initial_connection_window_size(16711681 + 65535)
5858
.headers_pseudo_order(
5959
PseudoOrder::builder()

src/core/client/conn/http1.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ where
8989
/// are subject to change at any time.
9090
#[derive(Clone, Debug)]
9191
pub struct Builder {
92-
config: Http1Options,
92+
opts: Http1Options,
9393
}
9494

9595
// ===== impl SendRequest
@@ -228,13 +228,14 @@ impl Builder {
228228
#[inline]
229229
pub fn new() -> Builder {
230230
Builder {
231-
config: Default::default(),
231+
opts: Default::default(),
232232
}
233233
}
234234

235-
pub fn config(&mut self, opts: Option<Http1Options>) {
236-
if let Some(config) = opts {
237-
self.config = config;
235+
/// Provide a options configuration for the HTTP/1 connection.
236+
pub fn options(&mut self, opts: Option<Http1Options>) {
237+
if let Some(opts) = opts {
238+
self.opts = opts;
238239
}
239240
}
240241

@@ -253,7 +254,7 @@ impl Builder {
253254
B::Data: Send,
254255
B::Error: Into<BoxError>,
255256
{
256-
let opts = self.config.clone();
257+
let opts = self.opts.clone();
257258

258259
async move {
259260
trace!("client handshake HTTP/1");

src/core/client/conn/http2.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ where
6262
/// are subject to change at any time.
6363
#[derive(Clone, Debug)]
6464
pub struct Builder<Ex> {
65-
pub(super) exec: Ex,
66-
pub(super) timer: Time,
67-
config: Http2Options,
65+
exec: Ex,
66+
timer: Time,
67+
opts: Http2Options,
6868
}
6969

7070
// ===== impl SendRequest
@@ -194,7 +194,7 @@ where
194194
Builder {
195195
exec,
196196
timer: Time::Empty,
197-
config: Default::default(),
197+
opts: Default::default(),
198198
}
199199
}
200200

@@ -206,10 +206,10 @@ where
206206
self.timer = Time::Timer(Arc::new(timer));
207207
}
208208

209-
/// Provide a configuration for HTTP/2.
210-
pub fn config(&mut self, opts: Option<Http2Options>) {
211-
if let Some(config) = opts {
212-
self.config = config;
209+
/// Provide a options configuration for the HTTP/2 connection.
210+
pub fn options(&mut self, opts: Option<Http2Options>) {
211+
if let Some(opts) = opts {
212+
self.opts = opts;
213213
}
214214
}
215215

@@ -229,7 +229,7 @@ where
229229
B::Error: Into<BoxError>,
230230
Ex: Http2ClientConnExec<B, T> + Unpin,
231231
{
232-
let opts = self.clone();
232+
let builder = self.clone();
233233

234234
async move {
235235
trace!("client handshake HTTP/2");
@@ -238,9 +238,10 @@ where
238238
let h2 = proto::h2::client::handshake(
239239
io,
240240
rx,
241-
&opts.config.h2_builder,
242-
opts.exec,
243-
opts.timer,
241+
builder.opts.builder,
242+
builder.opts.ping_config,
243+
builder.exec,
244+
builder.timer,
244245
)
245246
.await?;
246247
Ok((

src/core/client/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ where
295295
if let Some(opts) = transport_options {
296296
let (tls, http1, http2) = opts.into_parts();
297297
tls_options = tls;
298-
this.h1_builder.config(http1);
299-
this.h2_builder.config(http2);
298+
this.h1_builder.options(http1);
299+
this.h2_builder.options(http2);
300300
}
301301

302302
let conn_req = ConnRequest {
@@ -1131,13 +1131,13 @@ impl Builder {
11311131

11321132
/// Provide a configuration for HTTP/1.
11331133
pub fn http1_options(&mut self, opts: Option<Http1Options>) -> &mut Self {
1134-
self.h1_builder.config(opts);
1134+
self.h1_builder.options(opts);
11351135
self
11361136
}
11371137

11381138
/// Provide a configuration for HTTP/2.
11391139
pub fn http2_options(&mut self, opts: Option<Http2Options>) -> &mut Self {
1140-
self.h2_builder.config(opts);
1140+
self.h2_builder.options(opts);
11411141
self
11421142
}
11431143

src/core/client/options/http1.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::core::proto;
88
#[must_use]
99
#[derive(Debug)]
1010
pub struct Http1OptionsBuilder {
11-
config: Http1Options,
11+
opts: Http1Options,
1212
}
1313

1414
/// HTTP/1 protocol options for customizing connection behavior.
@@ -29,7 +29,7 @@ pub struct Http1Options {
2929
impl Http1OptionsBuilder {
3030
/// Set the `http09_responses` field.
3131
pub fn http09_responses(mut self, enabled: bool) -> Self {
32-
self.config.h09_responses = enabled;
32+
self.opts.h09_responses = enabled;
3333
self
3434
}
3535

@@ -46,7 +46,7 @@ impl Http1OptionsBuilder {
4646
/// Default is `auto`. In this mode crate::core: will try to guess which
4747
/// mode to use
4848
pub fn writev(mut self, writev: Option<bool>) -> Self {
49-
self.config.h1_writev = writev;
49+
self.opts.h1_writev = writev;
5050
self
5151
}
5252

@@ -58,7 +58,7 @@ impl Http1OptionsBuilder {
5858
///
5959
/// Default is false.
6060
pub fn preserve_header_case(mut self, preserve_header_case: bool) -> Self {
61-
self.config.h1_preserve_header_case = preserve_header_case;
61+
self.opts.h1_preserve_header_case = preserve_header_case;
6262
self
6363
}
6464

@@ -76,7 +76,7 @@ impl Http1OptionsBuilder {
7676
///
7777
/// Default is 100.
7878
pub fn max_headers(mut self, max_headers: usize) -> Self {
79-
self.config.h1_max_headers = Some(max_headers);
79+
self.opts.h1_max_headers = Some(max_headers);
8080
self
8181
}
8282

@@ -86,8 +86,8 @@ impl Http1OptionsBuilder {
8686
///
8787
/// Default is an adaptive read buffer.
8888
pub fn read_buf_exact_size(mut self, sz: Option<usize>) -> Self {
89-
self.config.h1_read_buf_exact_size = sz;
90-
self.config.h1_max_buf_size = None;
89+
self.opts.h1_read_buf_exact_size = sz;
90+
self.opts.h1_max_buf_size = None;
9191
self
9292
}
9393

@@ -107,8 +107,8 @@ impl Http1OptionsBuilder {
107107
"the max_buf_size cannot be smaller than the minimum that h1 specifies."
108108
);
109109

110-
self.config.h1_max_buf_size = Some(max);
111-
self.config.h1_read_buf_exact_size = None;
110+
self.opts.h1_max_buf_size = Some(max);
111+
self.opts.h1_read_buf_exact_size = None;
112112
self
113113
}
114114

@@ -130,7 +130,7 @@ impl Http1OptionsBuilder {
130130
///
131131
/// [RFC 7230 Section 3.2.4.]: https://tools.ietf.org/html/rfc7230#section-3.2.4
132132
pub fn allow_spaces_after_header_name_in_responses(mut self, enabled: bool) -> Self {
133-
self.config
133+
self.opts
134134
.h1_parser_config
135135
.allow_spaces_after_header_name_in_responses(enabled);
136136
self
@@ -144,7 +144,7 @@ impl Http1OptionsBuilder {
144144
///
145145
/// Default is false.
146146
pub fn ignore_invalid_headers_in_responses(mut self, enabled: bool) -> Self {
147-
self.config
147+
self.opts
148148
.h1_parser_config
149149
.ignore_invalid_headers_in_responses(enabled);
150150
self
@@ -155,7 +155,7 @@ impl Http1OptionsBuilder {
155155
mut self,
156156
allow_obsolete_multiline_headers_in_responses: bool,
157157
) -> Self {
158-
self.config
158+
self.opts
159159
.h1_parser_config
160160
.allow_obsolete_multiline_headers_in_responses(
161161
allow_obsolete_multiline_headers_in_responses,
@@ -165,15 +165,15 @@ impl Http1OptionsBuilder {
165165

166166
/// Build the `Http1Options` instance.
167167
pub fn build(self) -> Http1Options {
168-
self.config
168+
self.opts
169169
}
170170
}
171171

172172
impl Http1Options {
173173
/// Create a new `Http1OptionsBuilder`.
174174
pub fn builder() -> Http1OptionsBuilder {
175175
Http1OptionsBuilder {
176-
config: Http1Options::default(),
176+
opts: Http1Options::default(),
177177
}
178178
}
179179
}

0 commit comments

Comments
 (0)