wreq 1.2.5 → 1.2.6
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 +4 -4
- data/Cargo.lock +20 -13
- data/Cargo.toml +10 -2
- data/crates/wreq-util/src/emulate/macros.rs +12 -10
- data/crates/wreq-util/src/emulate/profile/chrome/header.rs +18 -3
- data/crates/wreq-util/src/emulate/profile/firefox/header.rs +16 -0
- data/crates/wreq-util/src/emulate/profile/opera/header.rs +6 -7
- data/crates/wreq-util/tests/client.rs +103 -1
- data/lib/wreq.rb +70 -45
- data/lib/wreq_ruby/body.rb +29 -11
- data/lib/wreq_ruby/client.rb +88 -55
- data/lib/wreq_ruby/cookie.rb +79 -19
- data/lib/wreq_ruby/emulate.rb +74 -6
- data/lib/wreq_ruby/error.rb +5 -7
- data/lib/wreq_ruby/http.rb +74 -0
- data/lib/wreq_ruby/response.rb +3 -0
- data/script/build_windows_gnu.ps1 +6 -0
- data/src/arch.rs +22 -0
- data/src/client/body/form.rs +2 -0
- data/src/client/body/json.rs +47 -14
- data/src/client/body/stream.rs +147 -43
- data/src/client/body.rs +11 -15
- data/src/client/param.rs +7 -7
- data/src/client/req.rs +87 -47
- data/src/client/resp.rs +23 -24
- data/src/client.rs +310 -230
- data/src/cookie.rs +280 -87
- data/src/emulate.rs +85 -50
- data/src/error.rs +198 -41
- data/src/extractor.rs +16 -76
- data/src/header.rs +146 -23
- data/src/http.rs +62 -33
- data/src/lib.rs +26 -20
- data/src/macros.rs +71 -46
- data/src/options.rs +284 -0
- data/src/rt.rs +22 -11
- data/src/serde/de/array_deserializer.rs +48 -0
- data/src/serde/de/array_enumerator.rs +59 -0
- data/src/serde/de/deserializer.rs +307 -0
- data/src/serde/de/enum_deserializer.rs +47 -0
- data/src/serde/de/hash_deserializer.rs +89 -0
- data/src/serde/de/number_deserializer.rs +51 -0
- data/src/serde/de/variant_deserializer.rs +101 -0
- data/src/serde/de.rs +33 -0
- data/src/serde/error.rs +146 -0
- data/src/serde/ser/enums.rs +14 -0
- data/src/serde/ser/map_serializer.rs +56 -0
- data/src/serde/ser/seq_serializer.rs +71 -0
- data/src/serde/ser/serializer.rs +194 -0
- data/src/serde/ser/struct_serializer.rs +106 -0
- data/src/serde/ser/struct_variant_serializer.rs +44 -0
- data/src/serde/ser/tuple_variant_serializer.rs +41 -0
- data/src/serde/ser.rs +18 -0
- data/src/serde/tests.rs +237 -0
- data/src/serde.rs +202 -0
- data/test/body_sender_test.rb +246 -0
- data/test/cookie_test.rb +211 -10
- data/test/json_precision_test.rb +209 -0
- data/test/option_validation_test.rb +311 -0
- data/test/value_semantics_test.rb +238 -0
- metadata +25 -2
- data/src/header/helper.rs +0 -112
data/src/client.rs
CHANGED
|
@@ -6,38 +6,38 @@ pub mod resp;
|
|
|
6
6
|
|
|
7
7
|
use std::{net::IpAddr, time::Duration};
|
|
8
8
|
|
|
9
|
-
use
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
use serde::Deserialize;
|
|
9
|
+
use ::serde::Deserialize;
|
|
10
|
+
use magnus::{Module, Object, RModule, Ruby, TryConvert, Value, function, method, typed_data::Obj};
|
|
13
11
|
use wreq::Proxy;
|
|
14
12
|
|
|
15
13
|
use crate::{
|
|
14
|
+
arch::{SUPPORTS_INTERFACE, SUPPORTS_TCP_USER_TIMEOUT},
|
|
16
15
|
client::{req::execute_request, resp::Response},
|
|
17
16
|
cookie::Jar,
|
|
18
17
|
emulate::Emulation,
|
|
19
|
-
error::
|
|
18
|
+
error::wreq_error,
|
|
20
19
|
extractor::Extractor,
|
|
21
20
|
gvl,
|
|
22
21
|
header::{Headers, OrigHeaders, UserAgent},
|
|
23
22
|
http::Method,
|
|
23
|
+
options::{NativeOption, Options},
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
/// A builder for `Client`.
|
|
27
27
|
#[derive(Default, Deserialize)]
|
|
28
28
|
struct Builder {
|
|
29
29
|
// The emulation option for the client.
|
|
30
|
-
#[serde(
|
|
31
|
-
emulation:
|
|
30
|
+
#[serde(default)]
|
|
31
|
+
emulation: NativeOption<Emulation>,
|
|
32
32
|
/// The user agent to use for the client.
|
|
33
|
-
#[serde(
|
|
34
|
-
user_agent:
|
|
33
|
+
#[serde(default)]
|
|
34
|
+
user_agent: NativeOption<UserAgent>,
|
|
35
35
|
/// The headers to use for the client.
|
|
36
|
-
#[serde(
|
|
37
|
-
headers:
|
|
36
|
+
#[serde(default)]
|
|
37
|
+
headers: NativeOption<Headers>,
|
|
38
38
|
/// The original headers to use for the client.
|
|
39
|
-
#[serde(
|
|
40
|
-
orig_headers:
|
|
39
|
+
#[serde(default)]
|
|
40
|
+
orig_headers: NativeOption<OrigHeaders>,
|
|
41
41
|
/// Whether to use referer.
|
|
42
42
|
referer: Option<bool>,
|
|
43
43
|
/// Whether to allow redirects.
|
|
@@ -49,8 +49,8 @@ struct Builder {
|
|
|
49
49
|
/// Whether to use cookie store.
|
|
50
50
|
cookie_store: Option<bool>,
|
|
51
51
|
/// Whether to use cookie store provider.
|
|
52
|
-
#[serde(
|
|
53
|
-
cookie_provider:
|
|
52
|
+
#[serde(default)]
|
|
53
|
+
cookie_provider: NativeOption<Jar>,
|
|
54
54
|
|
|
55
55
|
// ========= Timeout options =========
|
|
56
56
|
/// The timeout to use for the client. (in seconds)
|
|
@@ -68,7 +68,7 @@ struct Builder {
|
|
|
68
68
|
/// Set the number of retries for TCP keepalive.
|
|
69
69
|
tcp_keepalive_retries: Option<u32>,
|
|
70
70
|
/// Set an optional user timeout for TCP sockets. (in seconds)
|
|
71
|
-
#[
|
|
71
|
+
#[allow(dead_code)]
|
|
72
72
|
tcp_user_timeout: Option<u64>,
|
|
73
73
|
/// Set that all sockets have `NO_DELAY` set.
|
|
74
74
|
tcp_nodelay: Option<bool>,
|
|
@@ -92,15 +92,15 @@ struct Builder {
|
|
|
92
92
|
https_only: Option<bool>,
|
|
93
93
|
|
|
94
94
|
// ========= TLS options =========
|
|
95
|
-
/// Whether to verify
|
|
95
|
+
/// Whether to verify TLS certificates.
|
|
96
96
|
verify: Option<bool>,
|
|
97
97
|
|
|
98
98
|
// ========= Network options =========
|
|
99
99
|
/// Whether to disable the proxy for the client.
|
|
100
100
|
no_proxy: Option<bool>,
|
|
101
101
|
/// The proxy to use for the client.
|
|
102
|
-
#[serde(
|
|
103
|
-
proxy:
|
|
102
|
+
#[serde(default)]
|
|
103
|
+
proxy: NativeOption<Proxy>,
|
|
104
104
|
/// Bind to a local IP Address.
|
|
105
105
|
local_address: Option<IpAddr>,
|
|
106
106
|
/// Bind to an interface by `SO_BINDTODEVICE`.
|
|
@@ -118,42 +118,65 @@ struct Builder {
|
|
|
118
118
|
zstd: Option<bool>,
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
#[derive(Clone
|
|
121
|
+
#[derive(Clone)]
|
|
122
122
|
#[magnus::wrap(class = "Wreq::Client", free_immediately, size)]
|
|
123
123
|
pub struct Client(wreq::Client);
|
|
124
124
|
|
|
125
125
|
// ===== impl Builder =====
|
|
126
126
|
|
|
127
127
|
impl Builder {
|
|
128
|
-
/// Create a new [`Builder`] from Ruby
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
128
|
+
/// Create a new [`Builder`] from a Ruby options Hash.
|
|
129
|
+
///
|
|
130
|
+
/// # Errors
|
|
131
|
+
///
|
|
132
|
+
/// Returns `ArgumentError` for unknown, duplicate, conflicting,
|
|
133
|
+
/// ineffective, or platform-specific options. Known values retain their
|
|
134
|
+
/// Ruby conversion error class and include the option name.
|
|
135
|
+
fn from_options(options: Options<'_>) -> Result<Self, magnus::Error> {
|
|
136
|
+
let options = options.validate_keys::<Self>()?;
|
|
137
|
+
let mut builder = options
|
|
138
|
+
.validator()
|
|
139
|
+
.reject_unsupported(stringify!(tcp_user_timeout), SUPPORTS_TCP_USER_TIMEOUT)
|
|
140
|
+
.reject_unsupported(stringify!(interface), SUPPORTS_INTERFACE)
|
|
141
|
+
.finish()?
|
|
142
|
+
.deserialize::<Self>()?;
|
|
143
|
+
|
|
144
|
+
options
|
|
145
|
+
.validator()
|
|
146
|
+
.reject_conflicts([
|
|
147
|
+
(stringify!(http1_only), builder.http1_only == Some(true)),
|
|
148
|
+
(stringify!(http2_only), builder.http2_only == Some(true)),
|
|
149
|
+
])
|
|
150
|
+
.reject_conflicts([
|
|
151
|
+
(stringify!(proxy), options.is_non_nil(stringify!(proxy))),
|
|
152
|
+
(stringify!(no_proxy), builder.no_proxy == Some(true)),
|
|
153
|
+
])
|
|
154
|
+
.require_when_present(
|
|
155
|
+
stringify!(max_redirects),
|
|
156
|
+
builder.max_redirects.is_some(),
|
|
157
|
+
builder.allow_redirects == Some(true),
|
|
158
|
+
":allow_redirects to be true",
|
|
159
|
+
)
|
|
160
|
+
.finish()?;
|
|
161
|
+
|
|
162
|
+
extract_native_option!(
|
|
163
|
+
options,
|
|
164
|
+
builder,
|
|
165
|
+
emulation,
|
|
166
|
+
Obj<Emulation> => |value| (*value).clone()
|
|
167
|
+
);
|
|
168
|
+
extract_native_option!(options, builder, user_agent);
|
|
169
|
+
extract_native_option!(options, builder, headers);
|
|
170
|
+
extract_native_option!(options, builder, orig_headers);
|
|
171
|
+
extract_native_option!(
|
|
172
|
+
options,
|
|
173
|
+
builder,
|
|
174
|
+
cookie_provider,
|
|
175
|
+
Obj<Jar> => |value| (*value).clone()
|
|
176
|
+
);
|
|
177
|
+
builder
|
|
178
|
+
.proxy
|
|
179
|
+
.set(Extractor::<Proxy>::try_convert(options.as_value())?.into_inner());
|
|
157
180
|
|
|
158
181
|
Ok(builder)
|
|
159
182
|
}
|
|
@@ -163,234 +186,291 @@ impl Builder {
|
|
|
163
186
|
|
|
164
187
|
impl Client {
|
|
165
188
|
/// Create a new [`Client`] with the given keyword arguments.
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
builder
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
189
|
+
///
|
|
190
|
+
/// # Errors
|
|
191
|
+
///
|
|
192
|
+
/// Returns Ruby configuration errors from [`Builder::from_options`] or the
|
|
193
|
+
/// native fallible client builder. Extra positional arguments return
|
|
194
|
+
/// `ArgumentError`.
|
|
195
|
+
pub fn new(ruby: &Ruby, args: &[Value]) -> Result<Self, magnus::Error> {
|
|
196
|
+
Options::from_args(ruby, args, "client")?
|
|
197
|
+
.map(Builder::from_options)
|
|
198
|
+
.transpose()
|
|
199
|
+
.map(Option::unwrap_or_default)
|
|
200
|
+
.and_then(|params| Self::build(ruby, params))
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/// Build the default client through the same fallible path as `new`.
|
|
204
|
+
///
|
|
205
|
+
/// # Errors
|
|
206
|
+
///
|
|
207
|
+
/// Returns `Wreq::BuilderError`, `Wreq::TlsError`, or another mapped native
|
|
208
|
+
/// initialization error without unwinding through Ruby.
|
|
209
|
+
pub(crate) fn default_client(ruby: &Ruby) -> Result<Self, magnus::Error> {
|
|
210
|
+
Self::build(ruby, Builder::default())
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/// Apply validated parameters and build the native client without the GVL.
|
|
214
|
+
///
|
|
215
|
+
/// # Errors
|
|
216
|
+
///
|
|
217
|
+
/// Maps native build failures only after the GVL has been reacquired.
|
|
218
|
+
fn build(ruby: &Ruby, mut params: Builder) -> Result<Self, magnus::Error> {
|
|
219
|
+
let result = gvl::nogvl(|| {
|
|
220
|
+
let mut builder = wreq::Client::builder();
|
|
221
|
+
|
|
222
|
+
// Emulation options.
|
|
223
|
+
apply_option!(set_if_some_inner, builder, params.emulation, emulation);
|
|
224
|
+
|
|
225
|
+
// User agent options.
|
|
226
|
+
apply_option!(set_if_some_inner, builder, params.user_agent, user_agent);
|
|
227
|
+
|
|
228
|
+
// Headers options.
|
|
229
|
+
apply_option!(
|
|
230
|
+
set_if_some_into_inner,
|
|
231
|
+
builder,
|
|
232
|
+
params.headers,
|
|
233
|
+
default_headers
|
|
234
|
+
);
|
|
235
|
+
apply_option!(
|
|
236
|
+
set_if_some_inner,
|
|
237
|
+
builder,
|
|
238
|
+
params.orig_headers,
|
|
239
|
+
orig_headers
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
// Allow redirects options.
|
|
243
|
+
apply_option!(set_if_some, builder, params.referer, referer);
|
|
244
|
+
match params.allow_redirects {
|
|
245
|
+
Some(false) => {
|
|
246
|
+
builder = builder.redirect(wreq::redirect::Policy::none());
|
|
247
|
+
}
|
|
248
|
+
Some(true) => {
|
|
249
|
+
builder = builder.redirect(
|
|
250
|
+
params
|
|
251
|
+
.max_redirects
|
|
252
|
+
.take()
|
|
253
|
+
.map(wreq::redirect::Policy::limited)
|
|
254
|
+
.unwrap_or_default(),
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
None => {}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Cookie options.
|
|
261
|
+
apply_option!(set_if_some, builder, params.cookie_store, cookie_store);
|
|
262
|
+
apply_option!(
|
|
263
|
+
set_if_some_inner,
|
|
264
|
+
builder,
|
|
265
|
+
params.cookie_provider,
|
|
266
|
+
cookie_provider
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
// TCP options.
|
|
270
|
+
apply_option!(
|
|
271
|
+
set_if_some_map,
|
|
272
|
+
builder,
|
|
273
|
+
params.tcp_keepalive,
|
|
274
|
+
tcp_keepalive,
|
|
275
|
+
Duration::from_secs
|
|
276
|
+
);
|
|
277
|
+
apply_option!(
|
|
278
|
+
set_if_some_map,
|
|
279
|
+
builder,
|
|
280
|
+
params.tcp_keepalive_interval,
|
|
281
|
+
tcp_keepalive_interval,
|
|
282
|
+
Duration::from_secs
|
|
283
|
+
);
|
|
284
|
+
apply_option!(
|
|
285
|
+
set_if_some,
|
|
286
|
+
builder,
|
|
287
|
+
params.tcp_keepalive_retries,
|
|
288
|
+
tcp_keepalive_retries
|
|
289
|
+
);
|
|
290
|
+
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
|
|
291
|
+
apply_option!(
|
|
292
|
+
set_if_some_map,
|
|
293
|
+
builder,
|
|
294
|
+
params.tcp_user_timeout,
|
|
295
|
+
tcp_user_timeout,
|
|
296
|
+
Duration::from_secs
|
|
297
|
+
);
|
|
298
|
+
apply_option!(set_if_some, builder, params.tcp_nodelay, tcp_nodelay);
|
|
299
|
+
apply_option!(
|
|
300
|
+
set_if_some,
|
|
301
|
+
builder,
|
|
302
|
+
params.tcp_reuse_address,
|
|
303
|
+
tcp_reuse_address
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
// Timeout options.
|
|
307
|
+
apply_option!(
|
|
308
|
+
set_if_some_map,
|
|
309
|
+
builder,
|
|
310
|
+
params.timeout,
|
|
311
|
+
timeout,
|
|
312
|
+
Duration::from_secs
|
|
313
|
+
);
|
|
314
|
+
apply_option!(
|
|
315
|
+
set_if_some_map,
|
|
316
|
+
builder,
|
|
317
|
+
params.connect_timeout,
|
|
318
|
+
connect_timeout,
|
|
319
|
+
Duration::from_secs
|
|
320
|
+
);
|
|
321
|
+
apply_option!(
|
|
322
|
+
set_if_some_map,
|
|
323
|
+
builder,
|
|
324
|
+
params.read_timeout,
|
|
325
|
+
read_timeout,
|
|
326
|
+
Duration::from_secs
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
// Pool options.
|
|
330
|
+
apply_option!(
|
|
331
|
+
set_if_some_map,
|
|
332
|
+
builder,
|
|
333
|
+
params.pool_idle_timeout,
|
|
334
|
+
pool_idle_timeout,
|
|
335
|
+
Duration::from_secs
|
|
336
|
+
);
|
|
337
|
+
apply_option!(
|
|
338
|
+
set_if_some,
|
|
339
|
+
builder,
|
|
340
|
+
params.pool_max_idle_per_host,
|
|
341
|
+
pool_max_idle_per_host
|
|
342
|
+
);
|
|
343
|
+
apply_option!(set_if_some, builder, params.pool_max_size, pool_max_size);
|
|
344
|
+
|
|
345
|
+
// Protocol options.
|
|
346
|
+
apply_option!(set_if_true, builder, params.http1_only, http1_only, false);
|
|
347
|
+
apply_option!(set_if_true, builder, params.http2_only, http2_only, false);
|
|
348
|
+
apply_option!(set_if_some, builder, params.https_only, https_only);
|
|
349
|
+
|
|
350
|
+
// TLS options.
|
|
351
|
+
apply_option!(set_if_some, builder, params.verify, tls_cert_verification);
|
|
352
|
+
|
|
353
|
+
// Network options.
|
|
354
|
+
apply_option!(set_if_some, builder, params.proxy, proxy);
|
|
355
|
+
apply_option!(set_if_true, builder, params.no_proxy, no_proxy, false);
|
|
356
|
+
apply_option!(set_if_some, builder, params.local_address, local_address);
|
|
357
|
+
#[cfg(any(
|
|
358
|
+
target_os = "android",
|
|
359
|
+
target_os = "fuchsia",
|
|
360
|
+
target_os = "illumos",
|
|
361
|
+
target_os = "ios",
|
|
362
|
+
target_os = "linux",
|
|
363
|
+
target_os = "macos",
|
|
364
|
+
target_os = "solaris",
|
|
365
|
+
target_os = "tvos",
|
|
366
|
+
target_os = "visionos",
|
|
367
|
+
target_os = "watchos",
|
|
368
|
+
))]
|
|
369
|
+
apply_option!(set_if_some, builder, params.interface, interface);
|
|
370
|
+
|
|
371
|
+
// Compression options.
|
|
372
|
+
apply_option!(set_if_some, builder, params.gzip, gzip);
|
|
373
|
+
apply_option!(set_if_some, builder, params.brotli, brotli);
|
|
374
|
+
apply_option!(set_if_some, builder, params.deflate, deflate);
|
|
375
|
+
apply_option!(set_if_some, builder, params.zstd, zstd);
|
|
376
|
+
|
|
377
|
+
builder.build().map(Client)
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
// Ruby exceptions must be created after the GVL has been reacquired.
|
|
381
|
+
result.map_err(|err| wreq_error(ruby, err))
|
|
329
382
|
}
|
|
330
383
|
}
|
|
331
384
|
|
|
332
385
|
impl Client {
|
|
386
|
+
/// Send a request through a newly built default client.
|
|
387
|
+
///
|
|
388
|
+
/// Request arguments are validated before the native client is built, so
|
|
389
|
+
/// invalid options fail without initializing a connection pool.
|
|
390
|
+
pub(crate) fn request_with_default_client(
|
|
391
|
+
ruby: &Ruby,
|
|
392
|
+
args: &[Value],
|
|
393
|
+
) -> Result<Response, magnus::Error> {
|
|
394
|
+
let ((method, url), request) = extract_request!(args, (Obj<Method>, String));
|
|
395
|
+
let client = Self::default_client(ruby)?;
|
|
396
|
+
execute_request(ruby, client.0, *method, url, request)
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/// Send a request with `method` through a newly built default client.
|
|
400
|
+
///
|
|
401
|
+
/// Request arguments are validated before the native client is built, so
|
|
402
|
+
/// invalid options fail without initializing a connection pool.
|
|
403
|
+
pub(crate) fn execute_with_default_client(
|
|
404
|
+
ruby: &Ruby,
|
|
405
|
+
method: Method,
|
|
406
|
+
args: &[Value],
|
|
407
|
+
) -> Result<Response, magnus::Error> {
|
|
408
|
+
let ((url,), request) = extract_request!(args, (String,));
|
|
409
|
+
let client = Self::default_client(ruby)?;
|
|
410
|
+
execute_request(ruby, client.0, method, url, request)
|
|
411
|
+
}
|
|
412
|
+
|
|
333
413
|
/// Send a HTTP request.
|
|
334
414
|
#[inline]
|
|
335
|
-
pub fn request(rb_self: &Self, args: &[Value]) -> Result<Response, magnus::Error> {
|
|
415
|
+
pub fn request(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<Response, magnus::Error> {
|
|
336
416
|
let ((method, url), request) = extract_request!(args, (Obj<Method>, String));
|
|
337
|
-
execute_request(rb_self.0.clone(), *method, url, request)
|
|
417
|
+
execute_request(ruby, rb_self.0.clone(), *method, url, request)
|
|
338
418
|
}
|
|
339
419
|
|
|
340
420
|
/// Send a GET request.
|
|
341
421
|
#[inline]
|
|
342
|
-
pub fn get(rb_self: &Self, args: &[Value]) -> Result<Response, magnus::Error> {
|
|
422
|
+
pub fn get(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<Response, magnus::Error> {
|
|
343
423
|
let ((url,), request) = extract_request!(args, (String,));
|
|
344
|
-
execute_request(rb_self.0.clone(), Method::GET, url, request)
|
|
424
|
+
execute_request(ruby, rb_self.0.clone(), Method::GET, url, request)
|
|
345
425
|
}
|
|
346
426
|
|
|
347
427
|
/// Send a POST request.
|
|
348
428
|
#[inline]
|
|
349
|
-
pub fn post(rb_self: &Self, args: &[Value]) -> Result<Response, magnus::Error> {
|
|
429
|
+
pub fn post(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<Response, magnus::Error> {
|
|
350
430
|
let ((url,), request) = extract_request!(args, (String,));
|
|
351
|
-
execute_request(rb_self.0.clone(), Method::POST, url, request)
|
|
431
|
+
execute_request(ruby, rb_self.0.clone(), Method::POST, url, request)
|
|
352
432
|
}
|
|
353
433
|
|
|
354
434
|
/// Send a PUT request.
|
|
355
435
|
#[inline]
|
|
356
|
-
pub fn put(rb_self: &Self, args: &[Value]) -> Result<Response, magnus::Error> {
|
|
436
|
+
pub fn put(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<Response, magnus::Error> {
|
|
357
437
|
let ((url,), request) = extract_request!(args, (String,));
|
|
358
|
-
execute_request(rb_self.0.clone(), Method::PUT, url, request)
|
|
438
|
+
execute_request(ruby, rb_self.0.clone(), Method::PUT, url, request)
|
|
359
439
|
}
|
|
360
440
|
|
|
361
441
|
/// Send a DELETE request.
|
|
362
442
|
#[inline]
|
|
363
|
-
pub fn delete(rb_self: &Self, args: &[Value]) -> Result<Response, magnus::Error> {
|
|
443
|
+
pub fn delete(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<Response, magnus::Error> {
|
|
364
444
|
let ((url,), request) = extract_request!(args, (String,));
|
|
365
|
-
execute_request(rb_self.0.clone(), Method::DELETE, url, request)
|
|
445
|
+
execute_request(ruby, rb_self.0.clone(), Method::DELETE, url, request)
|
|
366
446
|
}
|
|
367
447
|
|
|
368
448
|
/// Send a HEAD request.
|
|
369
449
|
#[inline]
|
|
370
|
-
pub fn head(rb_self: &Self, args: &[Value]) -> Result<Response, magnus::Error> {
|
|
450
|
+
pub fn head(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<Response, magnus::Error> {
|
|
371
451
|
let ((url,), request) = extract_request!(args, (String,));
|
|
372
|
-
execute_request(rb_self.0.clone(), Method::HEAD, url, request)
|
|
452
|
+
execute_request(ruby, rb_self.0.clone(), Method::HEAD, url, request)
|
|
373
453
|
}
|
|
374
454
|
|
|
375
455
|
/// Send an OPTIONS request.
|
|
376
456
|
#[inline]
|
|
377
|
-
pub fn options(rb_self: &Self, args: &[Value]) -> Result<Response, magnus::Error> {
|
|
457
|
+
pub fn options(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<Response, magnus::Error> {
|
|
378
458
|
let ((url,), request) = extract_request!(args, (String,));
|
|
379
|
-
execute_request(rb_self.0.clone(), Method::OPTIONS, url, request)
|
|
459
|
+
execute_request(ruby, rb_self.0.clone(), Method::OPTIONS, url, request)
|
|
380
460
|
}
|
|
381
461
|
|
|
382
462
|
/// Send a TRACE request.
|
|
383
463
|
#[inline]
|
|
384
|
-
pub fn trace(rb_self: &Self, args: &[Value]) -> Result<Response, magnus::Error> {
|
|
464
|
+
pub fn trace(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<Response, magnus::Error> {
|
|
385
465
|
let ((url,), request) = extract_request!(args, (String,));
|
|
386
|
-
execute_request(rb_self.0.clone(), Method::TRACE, url, request)
|
|
466
|
+
execute_request(ruby, rb_self.0.clone(), Method::TRACE, url, request)
|
|
387
467
|
}
|
|
388
468
|
|
|
389
469
|
/// Send a PATCH request.
|
|
390
470
|
#[inline]
|
|
391
|
-
pub fn patch(rb_self: &Self, args: &[Value]) -> Result<Response, magnus::Error> {
|
|
471
|
+
pub fn patch(ruby: &Ruby, rb_self: &Self, args: &[Value]) -> Result<Response, magnus::Error> {
|
|
392
472
|
let ((url,), request) = extract_request!(args, (String,));
|
|
393
|
-
execute_request(rb_self.0.clone(), Method::PATCH, url, request)
|
|
473
|
+
execute_request(ruby, rb_self.0.clone(), Method::PATCH, url, request)
|
|
394
474
|
}
|
|
395
475
|
}
|
|
396
476
|
|