wreq 1.1.0 → 1.2.1
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 +216 -142
- data/Cargo.toml +5 -5
- data/README.md +5 -5
- data/examples/cookie.rb +24 -0
- data/examples/{emulation_request.rb → emulate_request.rb} +8 -8
- data/lib/wreq.rb +54 -64
- data/lib/wreq_ruby/client.rb +82 -72
- data/lib/wreq_ruby/cookie.rb +21 -9
- data/lib/wreq_ruby/{emulation.rb → emulate.rb} +57 -29
- data/lib/wreq_ruby/header.rb +8 -0
- data/lib/wreq_ruby/http.rb +28 -0
- data/lib/wreq_ruby/response.rb +22 -21
- data/src/client/body/stream.rs +9 -14
- data/src/client/req.rs +53 -42
- data/src/client/resp.rs +46 -40
- data/src/client.rs +44 -35
- data/src/cookie.rs +46 -11
- data/src/emulate.rs +183 -168
- data/src/error.rs +16 -0
- data/src/extractor.rs +3 -60
- data/src/header.rs +61 -7
- data/src/http.rs +16 -1
- data/src/macros.rs +5 -0
- data/src/rt.rs +0 -18
- data/test/client_cookie_test.rb +1 -1
- data/test/cookie_test.rb +30 -16
- data/test/emulation_test.rb +8 -8
- data/test/error_handling_test.rb +4 -1
- data/test/inspect_test.rb +125 -0
- data/test/orig_header_test.rb +115 -0
- data/test/request_test.rb +10 -0
- data/test/stream_test.rb +292 -2
- metadata +6 -3
data/src/emulate.rs
CHANGED
|
@@ -4,11 +4,11 @@ use magnus::{
|
|
|
4
4
|
};
|
|
5
5
|
|
|
6
6
|
define_ruby_enum!(
|
|
7
|
-
/// An emulation.
|
|
7
|
+
/// An emulation profile.
|
|
8
8
|
const,
|
|
9
|
-
|
|
10
|
-
"Wreq::
|
|
11
|
-
wreq_util::
|
|
9
|
+
Profile,
|
|
10
|
+
"Wreq::Profile",
|
|
11
|
+
wreq_util::Profile,
|
|
12
12
|
Chrome100,
|
|
13
13
|
Chrome101,
|
|
14
14
|
Chrome104,
|
|
@@ -48,6 +48,7 @@ define_ruby_enum!(
|
|
|
48
48
|
Chrome145,
|
|
49
49
|
Chrome146,
|
|
50
50
|
Chrome147,
|
|
51
|
+
Chrome148,
|
|
51
52
|
|
|
52
53
|
Edge101,
|
|
53
54
|
Edge122,
|
|
@@ -67,6 +68,7 @@ define_ruby_enum!(
|
|
|
67
68
|
Edge145,
|
|
68
69
|
Edge146,
|
|
69
70
|
Edge147,
|
|
71
|
+
Edge148,
|
|
70
72
|
|
|
71
73
|
Firefox109,
|
|
72
74
|
Firefox117,
|
|
@@ -86,6 +88,8 @@ define_ruby_enum!(
|
|
|
86
88
|
Firefox147,
|
|
87
89
|
Firefox148,
|
|
88
90
|
Firefox149,
|
|
91
|
+
Firefox150,
|
|
92
|
+
Firefox151,
|
|
89
93
|
|
|
90
94
|
SafariIos17_2,
|
|
91
95
|
SafariIos17_4_1,
|
|
@@ -110,6 +114,8 @@ define_ruby_enum!(
|
|
|
110
114
|
Safari26,
|
|
111
115
|
Safari26_1,
|
|
112
116
|
Safari26_2,
|
|
117
|
+
Safari26_3,
|
|
118
|
+
Safari26_4,
|
|
113
119
|
SafariIos26,
|
|
114
120
|
SafariIos26_2,
|
|
115
121
|
SafariIPad26,
|
|
@@ -139,14 +145,15 @@ define_ruby_enum!(
|
|
|
139
145
|
Opera128,
|
|
140
146
|
Opera129,
|
|
141
147
|
Opera130,
|
|
148
|
+
Opera131,
|
|
142
149
|
);
|
|
143
150
|
|
|
144
151
|
define_ruby_enum!(
|
|
145
|
-
/// An emulation
|
|
152
|
+
/// An emulation profile for OS.
|
|
146
153
|
const,
|
|
147
|
-
|
|
148
|
-
"Wreq::
|
|
149
|
-
wreq_util::
|
|
154
|
+
Platform,
|
|
155
|
+
"Wreq::Platform",
|
|
156
|
+
wreq_util::Platform,
|
|
150
157
|
Windows,
|
|
151
158
|
MacOS,
|
|
152
159
|
Linux,
|
|
@@ -157,19 +164,19 @@ define_ruby_enum!(
|
|
|
157
164
|
/// A struct to represent the `EmulationOption` class.
|
|
158
165
|
#[derive(Clone)]
|
|
159
166
|
#[magnus::wrap(class = "Wreq::Emulation", free_immediately, size)]
|
|
160
|
-
pub struct Emulation(pub wreq_util::
|
|
167
|
+
pub struct Emulation(pub wreq_util::Emulation);
|
|
161
168
|
|
|
162
|
-
// ===== impl
|
|
169
|
+
// ===== impl Profile =====
|
|
163
170
|
|
|
164
|
-
impl
|
|
171
|
+
impl Profile {
|
|
165
172
|
pub fn to_s(&self) -> String {
|
|
166
173
|
self.into_ffi().inspect()
|
|
167
174
|
}
|
|
168
175
|
}
|
|
169
176
|
|
|
170
|
-
// ===== impl
|
|
177
|
+
// ===== impl Platform =====
|
|
171
178
|
|
|
172
|
-
impl
|
|
179
|
+
impl Platform {
|
|
173
180
|
pub fn to_s(&self) -> String {
|
|
174
181
|
self.into_ffi().inspect()
|
|
175
182
|
}
|
|
@@ -179,31 +186,31 @@ impl EmulationOS {
|
|
|
179
186
|
|
|
180
187
|
impl Emulation {
|
|
181
188
|
fn new(ruby: &Ruby, args: &[Value]) -> Result<Self, Error> {
|
|
182
|
-
let mut
|
|
183
|
-
let mut
|
|
184
|
-
let mut
|
|
185
|
-
let mut
|
|
189
|
+
let mut profile = None;
|
|
190
|
+
let mut platform = None;
|
|
191
|
+
let mut http2 = None;
|
|
192
|
+
let mut headers = None;
|
|
186
193
|
|
|
187
194
|
if let Some(hash) = args.first().and_then(|v| RHash::from_value(*v)) {
|
|
188
|
-
if let Some(v) = hash.get(ruby.to_symbol(
|
|
189
|
-
|
|
195
|
+
if let Some(v) = hash.get(ruby.to_symbol(stringify!(profile))) {
|
|
196
|
+
profile = Some(Obj::<Profile>::try_convert(v)?);
|
|
190
197
|
}
|
|
191
|
-
if let Some(v) = hash.get(ruby.to_symbol(
|
|
192
|
-
|
|
198
|
+
if let Some(v) = hash.get(ruby.to_symbol(stringify!(platform))) {
|
|
199
|
+
platform = Some(Obj::<Platform>::try_convert(v)?);
|
|
193
200
|
}
|
|
194
|
-
if let Some(v) = hash.get(ruby.to_symbol(
|
|
195
|
-
|
|
201
|
+
if let Some(v) = hash.get(ruby.to_symbol(stringify!(http2))) {
|
|
202
|
+
http2 = Some(bool::try_convert(v)?);
|
|
196
203
|
}
|
|
197
|
-
if let Some(v) = hash.get(ruby.to_symbol(
|
|
198
|
-
|
|
204
|
+
if let Some(v) = hash.get(ruby.to_symbol(stringify!(headers))) {
|
|
205
|
+
headers = Some(bool::try_convert(v)?);
|
|
199
206
|
}
|
|
200
207
|
}
|
|
201
208
|
|
|
202
|
-
let emulation = wreq_util::
|
|
203
|
-
.
|
|
204
|
-
.
|
|
205
|
-
.
|
|
206
|
-
.
|
|
209
|
+
let emulation = wreq_util::Emulation::builder()
|
|
210
|
+
.profile(profile.map(|obj| obj.into_ffi()).unwrap_or_default())
|
|
211
|
+
.platform(platform.map(|os| os.into_ffi()).unwrap_or_default())
|
|
212
|
+
.http2(http2.unwrap_or(true))
|
|
213
|
+
.headers(headers.unwrap_or(true))
|
|
207
214
|
.build();
|
|
208
215
|
|
|
209
216
|
Ok(Self(emulation))
|
|
@@ -211,150 +218,158 @@ impl Emulation {
|
|
|
211
218
|
}
|
|
212
219
|
|
|
213
220
|
pub fn include(ruby: &Ruby, gem_module: &RModule) -> Result<(), Error> {
|
|
214
|
-
//
|
|
215
|
-
let
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
-
emulation_class.const_set("Edge122", EmulationDevice::Edge122)?;
|
|
258
|
-
emulation_class.const_set("Edge127", EmulationDevice::Edge127)?;
|
|
259
|
-
emulation_class.const_set("Edge131", EmulationDevice::Edge131)?;
|
|
260
|
-
emulation_class.const_set("Edge134", EmulationDevice::Edge134)?;
|
|
261
|
-
emulation_class.const_set("Edge135", EmulationDevice::Edge135)?;
|
|
262
|
-
emulation_class.const_set("Edge136", EmulationDevice::Edge136)?;
|
|
263
|
-
emulation_class.const_set("Edge137", EmulationDevice::Edge137)?;
|
|
264
|
-
emulation_class.const_set("Edge138", EmulationDevice::Edge138)?;
|
|
265
|
-
emulation_class.const_set("Edge139", EmulationDevice::Edge139)?;
|
|
266
|
-
emulation_class.const_set("Edge140", EmulationDevice::Edge140)?;
|
|
267
|
-
emulation_class.const_set("Edge141", EmulationDevice::Edge141)?;
|
|
268
|
-
emulation_class.const_set("Edge142", EmulationDevice::Edge142)?;
|
|
269
|
-
emulation_class.const_set("Edge143", EmulationDevice::Edge143)?;
|
|
270
|
-
emulation_class.const_set("Edge144", EmulationDevice::Edge144)?;
|
|
271
|
-
emulation_class.const_set("Edge145", EmulationDevice::Edge145)?;
|
|
272
|
-
emulation_class.const_set("Edge146", EmulationDevice::Edge146)?;
|
|
273
|
-
emulation_class.const_set("Edge147", EmulationDevice::Edge147)?;
|
|
221
|
+
// Profile enum binding
|
|
222
|
+
let profile = gem_module.define_class("Profile", ruby.class_object())?;
|
|
223
|
+
profile.define_method("to_s", method!(Profile::to_s, 0))?;
|
|
224
|
+
profile.const_set("Chrome100", Profile::Chrome100)?;
|
|
225
|
+
profile.const_set("Chrome101", Profile::Chrome101)?;
|
|
226
|
+
profile.const_set("Chrome104", Profile::Chrome104)?;
|
|
227
|
+
profile.const_set("Chrome105", Profile::Chrome105)?;
|
|
228
|
+
profile.const_set("Chrome106", Profile::Chrome106)?;
|
|
229
|
+
profile.const_set("Chrome107", Profile::Chrome107)?;
|
|
230
|
+
profile.const_set("Chrome108", Profile::Chrome108)?;
|
|
231
|
+
profile.const_set("Chrome109", Profile::Chrome109)?;
|
|
232
|
+
profile.const_set("Chrome110", Profile::Chrome110)?;
|
|
233
|
+
profile.const_set("Chrome114", Profile::Chrome114)?;
|
|
234
|
+
profile.const_set("Chrome116", Profile::Chrome116)?;
|
|
235
|
+
profile.const_set("Chrome117", Profile::Chrome117)?;
|
|
236
|
+
profile.const_set("Chrome118", Profile::Chrome118)?;
|
|
237
|
+
profile.const_set("Chrome119", Profile::Chrome119)?;
|
|
238
|
+
profile.const_set("Chrome120", Profile::Chrome120)?;
|
|
239
|
+
profile.const_set("Chrome123", Profile::Chrome123)?;
|
|
240
|
+
profile.const_set("Chrome124", Profile::Chrome124)?;
|
|
241
|
+
profile.const_set("Chrome126", Profile::Chrome126)?;
|
|
242
|
+
profile.const_set("Chrome127", Profile::Chrome127)?;
|
|
243
|
+
profile.const_set("Chrome128", Profile::Chrome128)?;
|
|
244
|
+
profile.const_set("Chrome129", Profile::Chrome129)?;
|
|
245
|
+
profile.const_set("Chrome130", Profile::Chrome130)?;
|
|
246
|
+
profile.const_set("Chrome131", Profile::Chrome131)?;
|
|
247
|
+
profile.const_set("Chrome132", Profile::Chrome132)?;
|
|
248
|
+
profile.const_set("Chrome133", Profile::Chrome133)?;
|
|
249
|
+
profile.const_set("Chrome134", Profile::Chrome134)?;
|
|
250
|
+
profile.const_set("Chrome135", Profile::Chrome135)?;
|
|
251
|
+
profile.const_set("Chrome136", Profile::Chrome136)?;
|
|
252
|
+
profile.const_set("Chrome137", Profile::Chrome137)?;
|
|
253
|
+
profile.const_set("Chrome138", Profile::Chrome138)?;
|
|
254
|
+
profile.const_set("Chrome139", Profile::Chrome139)?;
|
|
255
|
+
profile.const_set("Chrome140", Profile::Chrome140)?;
|
|
256
|
+
profile.const_set("Chrome141", Profile::Chrome141)?;
|
|
257
|
+
profile.const_set("Chrome142", Profile::Chrome142)?;
|
|
258
|
+
profile.const_set("Chrome143", Profile::Chrome143)?;
|
|
259
|
+
profile.const_set("Chrome144", Profile::Chrome144)?;
|
|
260
|
+
profile.const_set("Chrome145", Profile::Chrome145)?;
|
|
261
|
+
profile.const_set("Chrome146", Profile::Chrome146)?;
|
|
262
|
+
profile.const_set("Chrome147", Profile::Chrome147)?;
|
|
263
|
+
profile.const_set("Chrome148", Profile::Chrome148)?;
|
|
274
264
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
265
|
+
profile.const_set("Edge101", Profile::Edge101)?;
|
|
266
|
+
profile.const_set("Edge122", Profile::Edge122)?;
|
|
267
|
+
profile.const_set("Edge127", Profile::Edge127)?;
|
|
268
|
+
profile.const_set("Edge131", Profile::Edge131)?;
|
|
269
|
+
profile.const_set("Edge134", Profile::Edge134)?;
|
|
270
|
+
profile.const_set("Edge135", Profile::Edge135)?;
|
|
271
|
+
profile.const_set("Edge136", Profile::Edge136)?;
|
|
272
|
+
profile.const_set("Edge137", Profile::Edge137)?;
|
|
273
|
+
profile.const_set("Edge138", Profile::Edge138)?;
|
|
274
|
+
profile.const_set("Edge139", Profile::Edge139)?;
|
|
275
|
+
profile.const_set("Edge140", Profile::Edge140)?;
|
|
276
|
+
profile.const_set("Edge141", Profile::Edge141)?;
|
|
277
|
+
profile.const_set("Edge142", Profile::Edge142)?;
|
|
278
|
+
profile.const_set("Edge143", Profile::Edge143)?;
|
|
279
|
+
profile.const_set("Edge144", Profile::Edge144)?;
|
|
280
|
+
profile.const_set("Edge145", Profile::Edge145)?;
|
|
281
|
+
profile.const_set("Edge146", Profile::Edge146)?;
|
|
282
|
+
profile.const_set("Edge147", Profile::Edge147)?;
|
|
283
|
+
profile.const_set("Edge148", Profile::Edge148)?;
|
|
293
284
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
emulation_class.const_set("Safari26", EmulationDevice::Safari26)?;
|
|
315
|
-
emulation_class.const_set("Safari26_1", EmulationDevice::Safari26_1)?;
|
|
316
|
-
emulation_class.const_set("Safari26_2", EmulationDevice::Safari26_2)?;
|
|
317
|
-
emulation_class.const_set("SafariIos26", EmulationDevice::SafariIos26)?;
|
|
318
|
-
emulation_class.const_set("SafariIos26_2", EmulationDevice::SafariIos26_2)?;
|
|
319
|
-
emulation_class.const_set("SafariIPad26", EmulationDevice::SafariIPad26)?;
|
|
320
|
-
emulation_class.const_set("SafariIpad26_2", EmulationDevice::SafariIpad26_2)?;
|
|
285
|
+
profile.const_set("Firefox109", Profile::Firefox109)?;
|
|
286
|
+
profile.const_set("Firefox117", Profile::Firefox117)?;
|
|
287
|
+
profile.const_set("Firefox128", Profile::Firefox128)?;
|
|
288
|
+
profile.const_set("Firefox133", Profile::Firefox133)?;
|
|
289
|
+
profile.const_set("Firefox135", Profile::Firefox135)?;
|
|
290
|
+
profile.const_set("FirefoxPrivate135", Profile::FirefoxPrivate135)?;
|
|
291
|
+
profile.const_set("FirefoxAndroid135", Profile::FirefoxAndroid135)?;
|
|
292
|
+
profile.const_set("Firefox136", Profile::Firefox136)?;
|
|
293
|
+
profile.const_set("FirefoxPrivate136", Profile::FirefoxPrivate136)?;
|
|
294
|
+
profile.const_set("Firefox139", Profile::Firefox139)?;
|
|
295
|
+
profile.const_set("Firefox142", Profile::Firefox142)?;
|
|
296
|
+
profile.const_set("Firefox143", Profile::Firefox143)?;
|
|
297
|
+
profile.const_set("Firefox144", Profile::Firefox144)?;
|
|
298
|
+
profile.const_set("Firefox145", Profile::Firefox145)?;
|
|
299
|
+
profile.const_set("Firefox146", Profile::Firefox146)?;
|
|
300
|
+
profile.const_set("Firefox147", Profile::Firefox147)?;
|
|
301
|
+
profile.const_set("Firefox148", Profile::Firefox148)?;
|
|
302
|
+
profile.const_set("Firefox149", Profile::Firefox149)?;
|
|
303
|
+
profile.const_set("Firefox150", Profile::Firefox150)?;
|
|
304
|
+
profile.const_set("Firefox151", Profile::Firefox151)?;
|
|
321
305
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
306
|
+
profile.const_set("SafariIos17_2", Profile::SafariIos17_2)?;
|
|
307
|
+
profile.const_set("SafariIos17_4_1", Profile::SafariIos17_4_1)?;
|
|
308
|
+
profile.const_set("SafariIos16_5", Profile::SafariIos16_5)?;
|
|
309
|
+
profile.const_set("Safari15_3", Profile::Safari15_3)?;
|
|
310
|
+
profile.const_set("Safari15_5", Profile::Safari15_5)?;
|
|
311
|
+
profile.const_set("Safari15_6_1", Profile::Safari15_6_1)?;
|
|
312
|
+
profile.const_set("Safari16", Profile::Safari16)?;
|
|
313
|
+
profile.const_set("Safari16_5", Profile::Safari16_5)?;
|
|
314
|
+
profile.const_set("Safari17_0", Profile::Safari17_0)?;
|
|
315
|
+
profile.const_set("Safari17_2_1", Profile::Safari17_2_1)?;
|
|
316
|
+
profile.const_set("Safari17_4_1", Profile::Safari17_4_1)?;
|
|
317
|
+
profile.const_set("Safari17_5", Profile::Safari17_5)?;
|
|
318
|
+
profile.const_set("Safari17_6", Profile::Safari17_6)?;
|
|
319
|
+
profile.const_set("Safari18", Profile::Safari18)?;
|
|
320
|
+
profile.const_set("SafariIPad18", Profile::SafariIPad18)?;
|
|
321
|
+
profile.const_set("Safari18_2", Profile::Safari18_2)?;
|
|
322
|
+
profile.const_set("Safari18_3", Profile::Safari18_3)?;
|
|
323
|
+
profile.const_set("Safari18_3_1", Profile::Safari18_3_1)?;
|
|
324
|
+
profile.const_set("SafariIos18_1_1", Profile::SafariIos18_1_1)?;
|
|
325
|
+
profile.const_set("Safari18_5", Profile::Safari18_5)?;
|
|
326
|
+
profile.const_set("Safari26", Profile::Safari26)?;
|
|
327
|
+
profile.const_set("Safari26_1", Profile::Safari26_1)?;
|
|
328
|
+
profile.const_set("Safari26_2", Profile::Safari26_2)?;
|
|
329
|
+
profile.const_set("Safari26_3", Profile::Safari26_3)?;
|
|
330
|
+
profile.const_set("Safari26_4", Profile::Safari26_4)?;
|
|
331
|
+
profile.const_set("SafariIos26", Profile::SafariIos26)?;
|
|
332
|
+
profile.const_set("SafariIos26_2", Profile::SafariIos26_2)?;
|
|
333
|
+
profile.const_set("SafariIPad26", Profile::SafariIPad26)?;
|
|
334
|
+
profile.const_set("SafariIpad26_2", Profile::SafariIpad26_2)?;
|
|
330
335
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
emulation_class.const_set("Opera124", EmulationDevice::Opera124)?;
|
|
340
|
-
emulation_class.const_set("Opera125", EmulationDevice::Opera125)?;
|
|
341
|
-
emulation_class.const_set("Opera126", EmulationDevice::Opera126)?;
|
|
342
|
-
emulation_class.const_set("Opera127", EmulationDevice::Opera127)?;
|
|
343
|
-
emulation_class.const_set("Opera128", EmulationDevice::Opera128)?;
|
|
344
|
-
emulation_class.const_set("Opera129", EmulationDevice::Opera129)?;
|
|
345
|
-
emulation_class.const_set("Opera130", EmulationDevice::Opera130)?;
|
|
336
|
+
profile.const_set("OkHttp3_9", Profile::OkHttp3_9)?;
|
|
337
|
+
profile.const_set("OkHttp3_11", Profile::OkHttp3_11)?;
|
|
338
|
+
profile.const_set("OkHttp3_13", Profile::OkHttp3_13)?;
|
|
339
|
+
profile.const_set("OkHttp3_14", Profile::OkHttp3_14)?;
|
|
340
|
+
profile.const_set("OkHttp4_9", Profile::OkHttp4_9)?;
|
|
341
|
+
profile.const_set("OkHttp4_10", Profile::OkHttp4_10)?;
|
|
342
|
+
profile.const_set("OkHttp4_12", Profile::OkHttp4_12)?;
|
|
343
|
+
profile.const_set("OkHttp5", Profile::OkHttp5)?;
|
|
346
344
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
345
|
+
profile.const_set("Opera116", Profile::Opera116)?;
|
|
346
|
+
profile.const_set("Opera117", Profile::Opera117)?;
|
|
347
|
+
profile.const_set("Opera118", Profile::Opera118)?;
|
|
348
|
+
profile.const_set("Opera119", Profile::Opera119)?;
|
|
349
|
+
profile.const_set("Opera120", Profile::Opera120)?;
|
|
350
|
+
profile.const_set("Opera121", Profile::Opera121)?;
|
|
351
|
+
profile.const_set("Opera122", Profile::Opera122)?;
|
|
352
|
+
profile.const_set("Opera123", Profile::Opera123)?;
|
|
353
|
+
profile.const_set("Opera124", Profile::Opera124)?;
|
|
354
|
+
profile.const_set("Opera125", Profile::Opera125)?;
|
|
355
|
+
profile.const_set("Opera126", Profile::Opera126)?;
|
|
356
|
+
profile.const_set("Opera127", Profile::Opera127)?;
|
|
357
|
+
profile.const_set("Opera128", Profile::Opera128)?;
|
|
358
|
+
profile.const_set("Opera129", Profile::Opera129)?;
|
|
359
|
+
profile.const_set("Opera130", Profile::Opera130)?;
|
|
360
|
+
profile.const_set("Opera131", Profile::Opera131)?;
|
|
361
|
+
|
|
362
|
+
// Platform enum binding
|
|
363
|
+
let platform = gem_module.define_class("Platform", ruby.class_object())?;
|
|
364
|
+
platform.define_method("to_s", method!(Platform::to_s, 0))?;
|
|
365
|
+
platform.const_set("Windows", Platform::Windows)?;
|
|
366
|
+
platform.const_set("MacOS", Platform::MacOS)?;
|
|
367
|
+
platform.const_set("Linux", Platform::Linux)?;
|
|
368
|
+
platform.const_set("Android", Platform::Android)?;
|
|
369
|
+
platform.const_set("IOS", Platform::IOS)?;
|
|
355
370
|
|
|
356
371
|
// Emulation class binding
|
|
357
|
-
let
|
|
358
|
-
|
|
372
|
+
let emulation = gem_module.define_class("Emulation", ruby.class_object())?;
|
|
373
|
+
emulation.define_singleton_method("new", function!(Emulation::new, -1))?;
|
|
359
374
|
Ok(())
|
|
360
375
|
}
|
data/src/error.rs
CHANGED
|
@@ -85,6 +85,14 @@ pub fn interrupt_error() -> MagnusError {
|
|
|
85
85
|
MagnusError::new(ruby!().get_inner(&INTERRUPT_ERROR), "request interrupted")
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
/// LocalJumpError for methods that require a Ruby block.
|
|
89
|
+
pub fn no_block_given_error() -> MagnusError {
|
|
90
|
+
MagnusError::new(
|
|
91
|
+
ruby!().exception_local_jump_error(),
|
|
92
|
+
"no block given (yield)",
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
88
96
|
/// Map [`tokio::sync::mpsc::error::SendError`] to corresponding [`magnus::Error`]
|
|
89
97
|
pub fn mpsc_send_error_to_magnus<T>(err: SendError<T>) -> MagnusError {
|
|
90
98
|
MagnusError::new(
|
|
@@ -109,6 +117,14 @@ pub fn header_value_error_to_magnus(err: wreq::header::InvalidHeaderValue) -> Ma
|
|
|
109
117
|
)
|
|
110
118
|
}
|
|
111
119
|
|
|
120
|
+
/// Map type/value errors to corresponding [`magnus::Error`]
|
|
121
|
+
pub fn type_value_error_to_magnus(err: &str) -> MagnusError {
|
|
122
|
+
MagnusError::new(
|
|
123
|
+
ruby!().get_inner(&BUILDER_ERROR),
|
|
124
|
+
format!("type error: {err}"),
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
|
|
112
128
|
/// Map [`wreq::Error`] to corresponding [`magnus::Error`]
|
|
113
129
|
pub fn wreq_error_to_magnus(err: wreq::Error) -> MagnusError {
|
|
114
130
|
let error_msg = err.to_string();
|
data/src/extractor.rs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
use bytes::Bytes;
|
|
2
1
|
use magnus::{RArray, RHash, RString, Ruby, TryConvert, r_hash::ForEach};
|
|
3
2
|
use wreq::{
|
|
4
|
-
Proxy,
|
|
3
|
+
Proxy,
|
|
5
4
|
header::{HeaderMap, HeaderName, HeaderValue, OrigHeaderMap},
|
|
6
5
|
};
|
|
7
6
|
|
|
@@ -33,27 +32,6 @@ where
|
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
// ===== impl Extractor<Version> =====
|
|
37
|
-
|
|
38
|
-
impl ExtractorName for Version {
|
|
39
|
-
const NAME: &str = "version";
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
impl TryConvert for Extractor<Version> {
|
|
43
|
-
fn try_convert(value: magnus::Value) -> Result<Self, magnus::Error> {
|
|
44
|
-
let keyword = RHash::try_convert(value)?;
|
|
45
|
-
if let Some(version_val) = keyword.get(Version::NAME) {
|
|
46
|
-
return <&crate::http::Version>::try_convert(version_val)
|
|
47
|
-
.cloned()
|
|
48
|
-
.map(crate::http::Version::into_ffi)
|
|
49
|
-
.map(Some)
|
|
50
|
-
.map(Extractor);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
Ok(Extractor(None))
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
35
|
// ===== impl Extractor<HeaderValue> =====
|
|
58
36
|
|
|
59
37
|
impl ExtractorName for HeaderValue {
|
|
@@ -138,41 +116,6 @@ impl TryConvert for Extractor<OrigHeaderMap> {
|
|
|
138
116
|
}
|
|
139
117
|
}
|
|
140
118
|
|
|
141
|
-
// ===== impl Extractor<Vec<HeaderValue>> =====
|
|
142
|
-
|
|
143
|
-
impl ExtractorName for Vec<HeaderValue> {
|
|
144
|
-
const NAME: &str = "cookies";
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
impl TryConvert for Extractor<Vec<HeaderValue>> {
|
|
148
|
-
fn try_convert(value: magnus::Value) -> Result<Self, magnus::Error> {
|
|
149
|
-
use percent_encoding::{NON_ALPHANUMERIC, percent_encode};
|
|
150
|
-
|
|
151
|
-
let ruby = Ruby::get_with(value);
|
|
152
|
-
let keyword = RHash::try_convert(value)?;
|
|
153
|
-
|
|
154
|
-
if let Some(hash) = keyword
|
|
155
|
-
.get(ruby.to_symbol(Vec::<HeaderValue>::NAME))
|
|
156
|
-
.and_then(RHash::from_value)
|
|
157
|
-
{
|
|
158
|
-
let mut cookies = Vec::new();
|
|
159
|
-
hash.foreach(|name: RString, value: RString| {
|
|
160
|
-
let value = value.to_bytes();
|
|
161
|
-
let encoded_value = percent_encode(&value, NON_ALPHANUMERIC);
|
|
162
|
-
let cookie = format!("{name}={encoded_value}");
|
|
163
|
-
let header_value = HeaderValue::from_maybe_shared(Bytes::from(cookie))
|
|
164
|
-
.map_err(header_value_error_to_magnus)?;
|
|
165
|
-
cookies.push(header_value);
|
|
166
|
-
Ok(ForEach::Continue)
|
|
167
|
-
})?;
|
|
168
|
-
|
|
169
|
-
return Ok(Extractor(Some(cookies)));
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
Ok(Extractor(None))
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
119
|
// ===== impl Extractor<Proxy> =====
|
|
177
120
|
|
|
178
121
|
impl ExtractorName for Proxy {
|
|
@@ -182,9 +125,9 @@ impl ExtractorName for Proxy {
|
|
|
182
125
|
impl TryConvert for Extractor<Proxy> {
|
|
183
126
|
fn try_convert(value: magnus::Value) -> Result<Self, magnus::Error> {
|
|
184
127
|
let ruby = Ruby::get_with(value);
|
|
185
|
-
let
|
|
128
|
+
let rhash = RHash::try_convert(value)?;
|
|
186
129
|
|
|
187
|
-
if let Some(proxy) =
|
|
130
|
+
if let Some(proxy) = rhash
|
|
188
131
|
.get(ruby.to_symbol(Proxy::NAME))
|
|
189
132
|
.and_then(RString::from_value)
|
|
190
133
|
{
|