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/lib/wreq_ruby/client.rb
CHANGED
|
@@ -35,9 +35,11 @@ unless defined?(Wreq)
|
|
|
35
35
|
# @param user_agent [String, nil] Custom User-Agent header value.
|
|
36
36
|
# If not specified, a default user agent will be used.
|
|
37
37
|
#
|
|
38
|
-
# @param headers [Hash{String=>String}, nil] Default headers to include
|
|
38
|
+
# @param headers [Wreq::Headers, Hash{String=>String}, nil] Default headers to include
|
|
39
39
|
# in every request. Header names are case-insensitive. These headers
|
|
40
40
|
# can be overridden on a per-request basis.
|
|
41
|
+
# @param orig_headers [Array<String>, nil] Original header names used to
|
|
42
|
+
# preserve raw header order and HTTP/1 case-sensitive header handling.
|
|
41
43
|
#
|
|
42
44
|
# @param referer [Boolean, nil] Whether to automatically send Referer
|
|
43
45
|
# headers when following redirects. When true, the previous URL will
|
|
@@ -236,17 +238,14 @@ unless defined?(Wreq)
|
|
|
236
238
|
#
|
|
237
239
|
# @param method [Wreq::Method] HTTP method to use
|
|
238
240
|
# @param url [String] Target URL
|
|
239
|
-
# @param headers [Hash{String=>String}, nil] Custom headers for this request
|
|
240
|
-
# @param orig_headers [
|
|
241
|
+
# @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
|
|
242
|
+
# @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
|
|
241
243
|
# @param default_headers [Hash{String=>String}, nil] Default headers to merge
|
|
242
244
|
# @param query [Hash, nil] URL query parameters
|
|
243
|
-
# @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
|
|
244
|
-
# @param json [Object, nil] JSON body (will be serialized)
|
|
245
|
-
# @param body [String, IO, nil] Raw request body (string or stream)
|
|
246
245
|
# @param auth [String, nil] Authorization header value
|
|
247
246
|
# @param bearer_auth [String, nil] Bearer token for Authorization header
|
|
248
247
|
# @param basic_auth [Array<String>, nil] Username and password for basic auth
|
|
249
|
-
# @param cookies [
|
|
248
|
+
# @param cookies [Hash{String=>String}, String, nil] Cookies to send
|
|
250
249
|
# @param allow_redirects [Boolean, nil] Whether to follow redirects
|
|
251
250
|
# @param max_redirects [Integer, nil] Maximum number of redirects to follow
|
|
252
251
|
# @param gzip [Boolean, nil] Enable gzip compression
|
|
@@ -256,10 +255,13 @@ unless defined?(Wreq)
|
|
|
256
255
|
# @param timeout [Integer, nil] Total request timeout (seconds)
|
|
257
256
|
# @param read_timeout [Integer, nil] Per-chunk read timeout (seconds)
|
|
258
257
|
# @param proxy [String, nil] Proxy server URI
|
|
259
|
-
# @param local_address [String, nil] Bind the
|
|
258
|
+
# @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail.
|
|
260
259
|
# @param interface [String, nil] Bind the socket to a specific network interface via `SO_BINDTODEVICE` (e.g., "eth0", "wlan0", "tun0"). Effective only on systems that support the option (Linux/Android/Fuchsia) and typically requires privileges (root or CAP_NET_ADMIN).
|
|
261
260
|
# @param emulation [Wreq::Emulation, nil] Device/OS emulation for this request
|
|
262
261
|
# @param version [Wreq::Version, nil] HTTP version to use
|
|
262
|
+
# @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
|
|
263
|
+
# @param json [Object, nil] JSON body (will be serialized)
|
|
264
|
+
# @param body [String, IO, nil] Raw request body (string or stream)
|
|
263
265
|
# @return [Wreq::Response] HTTP response
|
|
264
266
|
def request(method, url, **options)
|
|
265
267
|
end
|
|
@@ -267,17 +269,14 @@ unless defined?(Wreq)
|
|
|
267
269
|
# Send an HTTP GET request.
|
|
268
270
|
#
|
|
269
271
|
# @param url [String] Target URL
|
|
270
|
-
# @param headers [Hash{String=>String}, nil] Custom headers for this request
|
|
271
|
-
# @param orig_headers [
|
|
272
|
+
# @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
|
|
273
|
+
# @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
|
|
272
274
|
# @param default_headers [Hash{String=>String}, nil] Default headers to merge
|
|
273
275
|
# @param query [Hash, nil] URL query parameters
|
|
274
|
-
# @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
|
|
275
|
-
# @param json [Object, nil] JSON body (will be serialized)
|
|
276
|
-
# @param body [String, IO, nil] Raw request body (string or stream)
|
|
277
276
|
# @param auth [String, nil] Authorization header value
|
|
278
277
|
# @param bearer_auth [String, nil] Bearer token for Authorization header
|
|
279
278
|
# @param basic_auth [Array<String>, nil] Username and password for basic auth
|
|
280
|
-
# @param cookies [
|
|
279
|
+
# @param cookies [Hash{String=>String}, String, nil] Cookies to send
|
|
281
280
|
# @param allow_redirects [Boolean, nil] Whether to follow redirects
|
|
282
281
|
# @param max_redirects [Integer, nil] Maximum number of redirects to follow
|
|
283
282
|
# @param gzip [Boolean, nil] Enable gzip compression
|
|
@@ -287,10 +286,13 @@ unless defined?(Wreq)
|
|
|
287
286
|
# @param timeout [Integer, nil] Total request timeout (seconds)
|
|
288
287
|
# @param read_timeout [Integer, nil] Per-chunk read timeout (seconds)
|
|
289
288
|
# @param proxy [String, nil] Proxy server URI
|
|
290
|
-
# @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful to originate
|
|
291
|
-
# @param interface [String, nil] Bind the socket to a network interface via `SO_BINDTODEVICE` (e.g., "eth0", "wlan0", "tun0").
|
|
289
|
+
# @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail.
|
|
290
|
+
# @param interface [String, nil] Bind the socket to a specific network interface via `SO_BINDTODEVICE` (e.g., "eth0", "wlan0", "tun0"). Effective only on systems that support the option (Linux/Android/Fuchsia) and typically requires privileges (root or CAP_NET_ADMIN).
|
|
292
291
|
# @param emulation [Wreq::Emulation, nil] Device/OS emulation for this request
|
|
293
292
|
# @param version [Wreq::Version, nil] HTTP version to use
|
|
293
|
+
# @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
|
|
294
|
+
# @param json [Object, nil] JSON body (will be serialized)
|
|
295
|
+
# @param body [String, IO, nil] Raw request body (string or stream)
|
|
294
296
|
# @return [Wreq::Response] HTTP response
|
|
295
297
|
def get(url, **options)
|
|
296
298
|
end
|
|
@@ -298,17 +300,14 @@ unless defined?(Wreq)
|
|
|
298
300
|
# Send an HTTP HEAD request.
|
|
299
301
|
#
|
|
300
302
|
# @param url [String] Target URL
|
|
301
|
-
# @param headers [Hash{String=>String}, nil] Custom headers for this request
|
|
302
|
-
# @param orig_headers [
|
|
303
|
+
# @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
|
|
304
|
+
# @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
|
|
303
305
|
# @param default_headers [Hash{String=>String}, nil] Default headers to merge
|
|
304
306
|
# @param query [Hash, nil] URL query parameters
|
|
305
|
-
# @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
|
|
306
|
-
# @param json [Object, nil] JSON body (will be serialized)
|
|
307
|
-
# @param body [String, IO, nil] Raw request body (string or stream)
|
|
308
307
|
# @param auth [String, nil] Authorization header value
|
|
309
308
|
# @param bearer_auth [String, nil] Bearer token for Authorization header
|
|
310
309
|
# @param basic_auth [Array<String>, nil] Username and password for basic auth
|
|
311
|
-
# @param cookies [
|
|
310
|
+
# @param cookies [Hash{String=>String}, String, nil] Cookies to send
|
|
312
311
|
# @param allow_redirects [Boolean, nil] Whether to follow redirects
|
|
313
312
|
# @param max_redirects [Integer, nil] Maximum number of redirects to follow
|
|
314
313
|
# @param gzip [Boolean, nil] Enable gzip compression
|
|
@@ -318,10 +317,13 @@ unless defined?(Wreq)
|
|
|
318
317
|
# @param timeout [Integer, nil] Total request timeout (seconds)
|
|
319
318
|
# @param read_timeout [Integer, nil] Per-chunk read timeout (seconds)
|
|
320
319
|
# @param proxy [String, nil] Proxy server URI
|
|
321
|
-
# @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful to originate
|
|
322
|
-
# @param interface [String, nil] Bind the socket to a network interface via `SO_BINDTODEVICE` (e.g., "eth0", "wlan0", "tun0").
|
|
320
|
+
# @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail.
|
|
321
|
+
# @param interface [String, nil] Bind the socket to a specific network interface via `SO_BINDTODEVICE` (e.g., "eth0", "wlan0", "tun0"). Effective only on systems that support the option (Linux/Android/Fuchsia) and typically requires privileges (root or CAP_NET_ADMIN).
|
|
323
322
|
# @param emulation [Wreq::Emulation, nil] Device/OS emulation for this request
|
|
324
323
|
# @param version [Wreq::Version, nil] HTTP version to use
|
|
324
|
+
# @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
|
|
325
|
+
# @param json [Object, nil] JSON body (will be serialized)
|
|
326
|
+
# @param body [String, IO, nil] Raw request body (string or stream)
|
|
325
327
|
# @return [Wreq::Response] HTTP response
|
|
326
328
|
def head(url, **options)
|
|
327
329
|
end
|
|
@@ -329,17 +331,14 @@ unless defined?(Wreq)
|
|
|
329
331
|
# Send an HTTP POST request.
|
|
330
332
|
#
|
|
331
333
|
# @param url [String] Target URL
|
|
332
|
-
# @param headers [Hash{String=>String}, nil] Custom headers for this request
|
|
333
|
-
# @param orig_headers [
|
|
334
|
+
# @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
|
|
335
|
+
# @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
|
|
334
336
|
# @param default_headers [Hash{String=>String}, nil] Default headers to merge
|
|
335
337
|
# @param query [Hash, nil] URL query parameters
|
|
336
|
-
# @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
|
|
337
|
-
# @param json [Object, nil] JSON body (will be serialized)
|
|
338
|
-
# @param body [String, IO, nil] Raw request body (string or stream)
|
|
339
338
|
# @param auth [String, nil] Authorization header value
|
|
340
339
|
# @param bearer_auth [String, nil] Bearer token for Authorization header
|
|
341
340
|
# @param basic_auth [Array<String>, nil] Username and password for basic auth
|
|
342
|
-
# @param cookies [
|
|
341
|
+
# @param cookies [Hash{String=>String}, String, nil] Cookies to send
|
|
343
342
|
# @param allow_redirects [Boolean, nil] Whether to follow redirects
|
|
344
343
|
# @param max_redirects [Integer, nil] Maximum number of redirects to follow
|
|
345
344
|
# @param gzip [Boolean, nil] Enable gzip compression
|
|
@@ -349,10 +348,13 @@ unless defined?(Wreq)
|
|
|
349
348
|
# @param timeout [Integer, nil] Total request timeout (seconds)
|
|
350
349
|
# @param read_timeout [Integer, nil] Per-chunk read timeout (seconds)
|
|
351
350
|
# @param proxy [String, nil] Proxy server URI
|
|
352
|
-
# @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful to originate
|
|
353
|
-
# @param interface [String, nil] Bind the socket to a network interface via `SO_BINDTODEVICE
|
|
351
|
+
# @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail.
|
|
352
|
+
# @param interface [String, nil] Bind the socket to a specific network interface via `SO_BINDTODEVICE` (e.g., "eth0", "wlan0", "tun0"). Effective only on systems that support the option (Linux/Android/Fuchsia) and typically requires privileges (root or CAP_NET_ADMIN).
|
|
354
353
|
# @param emulation [Wreq::Emulation, nil] Device/OS emulation for this request
|
|
355
354
|
# @param version [Wreq::Version, nil] HTTP version to use
|
|
355
|
+
# @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
|
|
356
|
+
# @param json [Object, nil] JSON body (will be serialized)
|
|
357
|
+
# @param body [String, IO, nil] Raw request body (string or stream)
|
|
356
358
|
# @return [Wreq::Response] HTTP response
|
|
357
359
|
def post(url, **options)
|
|
358
360
|
end
|
|
@@ -360,17 +362,14 @@ unless defined?(Wreq)
|
|
|
360
362
|
# Send an HTTP PUT request.
|
|
361
363
|
#
|
|
362
364
|
# @param url [String] Target URL
|
|
363
|
-
# @param headers [Hash{String=>String}, nil] Custom headers for this request
|
|
364
|
-
# @param orig_headers [
|
|
365
|
+
# @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
|
|
366
|
+
# @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
|
|
365
367
|
# @param default_headers [Hash{String=>String}, nil] Default headers to merge
|
|
366
368
|
# @param query [Hash, nil] URL query parameters
|
|
367
|
-
# @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
|
|
368
|
-
# @param json [Object, nil] JSON body (will be serialized)
|
|
369
|
-
# @param body [String, IO, nil] Raw request body (string or stream)
|
|
370
369
|
# @param auth [String, nil] Authorization header value
|
|
371
370
|
# @param bearer_auth [String, nil] Bearer token for Authorization header
|
|
372
371
|
# @param basic_auth [Array<String>, nil] Username and password for basic auth
|
|
373
|
-
# @param cookies [
|
|
372
|
+
# @param cookies [Hash{String=>String}, String, nil] Cookies to send
|
|
374
373
|
# @param allow_redirects [Boolean, nil] Whether to follow redirects
|
|
375
374
|
# @param max_redirects [Integer, nil] Maximum number of redirects to follow
|
|
376
375
|
# @param gzip [Boolean, nil] Enable gzip compression
|
|
@@ -380,10 +379,13 @@ unless defined?(Wreq)
|
|
|
380
379
|
# @param timeout [Integer, nil] Total request timeout (seconds)
|
|
381
380
|
# @param read_timeout [Integer, nil] Per-chunk read timeout (seconds)
|
|
382
381
|
# @param proxy [String, nil] Proxy server URI
|
|
383
|
-
# @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful to originate
|
|
384
|
-
# @param interface [String, nil] Bind the socket to a network interface via `SO_BINDTODEVICE
|
|
382
|
+
# @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail.
|
|
383
|
+
# @param interface [String, nil] Bind the socket to a specific network interface via `SO_BINDTODEVICE` (e.g., "eth0", "wlan0", "tun0"). Effective only on systems that support the option (Linux/Android/Fuchsia) and typically requires privileges (root or CAP_NET_ADMIN).
|
|
385
384
|
# @param emulation [Wreq::Emulation, nil] Device/OS emulation for this request
|
|
386
385
|
# @param version [Wreq::Version, nil] HTTP version to use
|
|
386
|
+
# @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
|
|
387
|
+
# @param json [Object, nil] JSON body (will be serialized)
|
|
388
|
+
# @param body [String, IO, nil] Raw request body (string or stream)
|
|
387
389
|
# @return [Wreq::Response] HTTP response
|
|
388
390
|
def put(url, **options)
|
|
389
391
|
end
|
|
@@ -391,17 +393,14 @@ unless defined?(Wreq)
|
|
|
391
393
|
# Send an HTTP DELETE request.
|
|
392
394
|
#
|
|
393
395
|
# @param url [String] Target URL
|
|
394
|
-
# @param headers [Hash{String=>String}, nil] Custom headers for this request
|
|
395
|
-
# @param orig_headers [
|
|
396
|
+
# @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
|
|
397
|
+
# @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
|
|
396
398
|
# @param default_headers [Hash{String=>String}, nil] Default headers to merge
|
|
397
399
|
# @param query [Hash, nil] URL query parameters
|
|
398
|
-
# @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
|
|
399
|
-
# @param json [Object, nil] JSON body (will be serialized)
|
|
400
|
-
# @param body [String, IO, nil] Raw request body (string or stream)
|
|
401
400
|
# @param auth [String, nil] Authorization header value
|
|
402
401
|
# @param bearer_auth [String, nil] Bearer token for Authorization header
|
|
403
402
|
# @param basic_auth [Array<String>, nil] Username and password for basic auth
|
|
404
|
-
# @param cookies [
|
|
403
|
+
# @param cookies [Hash{String=>String}, String, nil] Cookies to send
|
|
405
404
|
# @param allow_redirects [Boolean, nil] Whether to follow redirects
|
|
406
405
|
# @param max_redirects [Integer, nil] Maximum number of redirects to follow
|
|
407
406
|
# @param gzip [Boolean, nil] Enable gzip compression
|
|
@@ -411,10 +410,13 @@ unless defined?(Wreq)
|
|
|
411
410
|
# @param timeout [Integer, nil] Total request timeout (seconds)
|
|
412
411
|
# @param read_timeout [Integer, nil] Per-chunk read timeout (seconds)
|
|
413
412
|
# @param proxy [String, nil] Proxy server URI
|
|
414
|
-
# @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful to originate
|
|
415
|
-
# @param interface [String, nil] Bind the socket to a network interface via `SO_BINDTODEVICE
|
|
413
|
+
# @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail.
|
|
414
|
+
# @param interface [String, nil] Bind the socket to a specific network interface via `SO_BINDTODEVICE` (e.g., "eth0", "wlan0", "tun0"). Effective only on systems that support the option (Linux/Android/Fuchsia) and typically requires privileges (root or CAP_NET_ADMIN).
|
|
416
415
|
# @param emulation [Wreq::Emulation, nil] Device/OS emulation for this request
|
|
417
416
|
# @param version [Wreq::Version, nil] HTTP version to use
|
|
417
|
+
# @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
|
|
418
|
+
# @param json [Object, nil] JSON body (will be serialized)
|
|
419
|
+
# @param body [String, IO, nil] Raw request body (string or stream)
|
|
418
420
|
# @return [Wreq::Response] HTTP response
|
|
419
421
|
def delete(url, **options)
|
|
420
422
|
end
|
|
@@ -422,17 +424,14 @@ unless defined?(Wreq)
|
|
|
422
424
|
# Send an HTTP OPTIONS request.
|
|
423
425
|
#
|
|
424
426
|
# @param url [String] Target URL
|
|
425
|
-
# @param headers [Hash{String=>String}, nil] Custom headers for this request
|
|
426
|
-
# @param orig_headers [
|
|
427
|
+
# @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
|
|
428
|
+
# @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
|
|
427
429
|
# @param default_headers [Hash{String=>String}, nil] Default headers to merge
|
|
428
430
|
# @param query [Hash, nil] URL query parameters
|
|
429
|
-
# @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
|
|
430
|
-
# @param json [Object, nil] JSON body (will be serialized)
|
|
431
|
-
# @param body [String, IO, nil] Raw request body (string or stream)
|
|
432
431
|
# @param auth [String, nil] Authorization header value
|
|
433
432
|
# @param bearer_auth [String, nil] Bearer token for Authorization header
|
|
434
433
|
# @param basic_auth [Array<String>, nil] Username and password for basic auth
|
|
435
|
-
# @param cookies [
|
|
434
|
+
# @param cookies [Hash{String=>String}, String, nil] Cookies to send
|
|
436
435
|
# @param allow_redirects [Boolean, nil] Whether to follow redirects
|
|
437
436
|
# @param max_redirects [Integer, nil] Maximum number of redirects to follow
|
|
438
437
|
# @param gzip [Boolean, nil] Enable gzip compression
|
|
@@ -442,10 +441,13 @@ unless defined?(Wreq)
|
|
|
442
441
|
# @param timeout [Integer, nil] Total request timeout (seconds)
|
|
443
442
|
# @param read_timeout [Integer, nil] Per-chunk read timeout (seconds)
|
|
444
443
|
# @param proxy [String, nil] Proxy server URI
|
|
445
|
-
# @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful to originate
|
|
446
|
-
# @param interface [String, nil] Bind the socket to a network interface via `SO_BINDTODEVICE
|
|
444
|
+
# @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail.
|
|
445
|
+
# @param interface [String, nil] Bind the socket to a specific network interface via `SO_BINDTODEVICE` (e.g., "eth0", "wlan0", "tun0"). Effective only on systems that support the option (Linux/Android/Fuchsia) and typically requires privileges (root or CAP_NET_ADMIN).
|
|
447
446
|
# @param emulation [Wreq::Emulation, nil] Device/OS emulation for this request
|
|
448
447
|
# @param version [Wreq::Version, nil] HTTP version to use
|
|
448
|
+
# @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
|
|
449
|
+
# @param json [Object, nil] JSON body (will be serialized)
|
|
450
|
+
# @param body [String, IO, nil] Raw request body (string or stream)
|
|
449
451
|
# @return [Wreq::Response] HTTP response
|
|
450
452
|
def options(url, **options)
|
|
451
453
|
end
|
|
@@ -453,17 +455,14 @@ unless defined?(Wreq)
|
|
|
453
455
|
# Send an HTTP TRACE request.
|
|
454
456
|
#
|
|
455
457
|
# @param url [String] Target URL
|
|
456
|
-
# @param headers [Hash{String=>String}, nil] Custom headers for this request
|
|
457
|
-
# @param orig_headers [
|
|
458
|
+
# @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
|
|
459
|
+
# @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
|
|
458
460
|
# @param default_headers [Hash{String=>String}, nil] Default headers to merge
|
|
459
461
|
# @param query [Hash, nil] URL query parameters
|
|
460
|
-
# @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
|
|
461
|
-
# @param json [Object, nil] JSON body (will be serialized)
|
|
462
|
-
# @param body [String, IO, nil] Raw request body (string or stream)
|
|
463
462
|
# @param auth [String, nil] Authorization header value
|
|
464
463
|
# @param bearer_auth [String, nil] Bearer token for Authorization header
|
|
465
464
|
# @param basic_auth [Array<String>, nil] Username and password for basic auth
|
|
466
|
-
# @param cookies [
|
|
465
|
+
# @param cookies [Hash{String=>String}, String, nil] Cookies to send
|
|
467
466
|
# @param allow_redirects [Boolean, nil] Whether to follow redirects
|
|
468
467
|
# @param max_redirects [Integer, nil] Maximum number of redirects to follow
|
|
469
468
|
# @param gzip [Boolean, nil] Enable gzip compression
|
|
@@ -473,10 +472,13 @@ unless defined?(Wreq)
|
|
|
473
472
|
# @param timeout [Integer, nil] Total request timeout (seconds)
|
|
474
473
|
# @param read_timeout [Integer, nil] Per-chunk read timeout (seconds)
|
|
475
474
|
# @param proxy [String, nil] Proxy server URI
|
|
476
|
-
# @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful to originate
|
|
477
|
-
# @param interface [String, nil] Bind the socket to a network interface via `SO_BINDTODEVICE
|
|
475
|
+
# @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail.
|
|
476
|
+
# @param interface [String, nil] Bind the socket to a specific network interface via `SO_BINDTODEVICE` (e.g., "eth0", "wlan0", "tun0"). Effective only on systems that support the option (Linux/Android/Fuchsia) and typically requires privileges (root or CAP_NET_ADMIN).
|
|
478
477
|
# @param emulation [Wreq::Emulation, nil] Device/OS emulation for this request
|
|
479
478
|
# @param version [Wreq::Version, nil] HTTP version to use
|
|
479
|
+
# @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
|
|
480
|
+
# @param json [Object, nil] JSON body (will be serialized)
|
|
481
|
+
# @param body [String, IO, nil] Raw request body (string or stream)
|
|
480
482
|
# @return [Wreq::Response] HTTP response
|
|
481
483
|
def trace(url, **options)
|
|
482
484
|
end
|
|
@@ -484,17 +486,14 @@ unless defined?(Wreq)
|
|
|
484
486
|
# Send an HTTP PATCH request.
|
|
485
487
|
#
|
|
486
488
|
# @param url [String] Target URL
|
|
487
|
-
# @param headers [Hash{String=>String}, nil] Custom headers for this request
|
|
488
|
-
# @param orig_headers [
|
|
489
|
+
# @param headers [Wreq::Headers, Hash{String=>String}, nil] Custom headers for this request
|
|
490
|
+
# @param orig_headers [Array<String>, nil] Original header names used to preserve raw header order and HTTP/1 case-sensitive header handling
|
|
489
491
|
# @param default_headers [Hash{String=>String}, nil] Default headers to merge
|
|
490
492
|
# @param query [Hash, nil] URL query parameters
|
|
491
|
-
# @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
|
|
492
|
-
# @param json [Object, nil] JSON body (will be serialized)
|
|
493
|
-
# @param body [String, IO, nil] Raw request body (string or stream)
|
|
494
493
|
# @param auth [String, nil] Authorization header value
|
|
495
494
|
# @param bearer_auth [String, nil] Bearer token for Authorization header
|
|
496
495
|
# @param basic_auth [Array<String>, nil] Username and password for basic auth
|
|
497
|
-
# @param cookies [
|
|
496
|
+
# @param cookies [Hash{String=>String}, String, nil] Cookies to send
|
|
498
497
|
# @param allow_redirects [Boolean, nil] Whether to follow redirects
|
|
499
498
|
# @param max_redirects [Integer, nil] Maximum number of redirects to follow
|
|
500
499
|
# @param gzip [Boolean, nil] Enable gzip compression
|
|
@@ -504,13 +503,24 @@ unless defined?(Wreq)
|
|
|
504
503
|
# @param timeout [Integer, nil] Total request timeout (seconds)
|
|
505
504
|
# @param read_timeout [Integer, nil] Per-chunk read timeout (seconds)
|
|
506
505
|
# @param proxy [String, nil] Proxy server URI
|
|
507
|
-
# @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful to originate
|
|
508
|
-
# @param interface [String, nil] Bind the socket to a network interface via `SO_BINDTODEVICE
|
|
506
|
+
# @param local_address [String, nil] Bind the request's local source IP address (IPv4/IPv6). Useful on multi-homed hosts to originate connections from a specific address or enforce source routing. Examples: "192.168.1.10", "10.0.0.5", "2001:db8::1". The address must exist on the host and be routable or the connection may fail.
|
|
507
|
+
# @param interface [String, nil] Bind the socket to a specific network interface via `SO_BINDTODEVICE` (e.g., "eth0", "wlan0", "tun0"). Effective only on systems that support the option (Linux/Android/Fuchsia) and typically requires privileges (root or CAP_NET_ADMIN).
|
|
509
508
|
# @param emulation [Wreq::Emulation, nil] Device/OS emulation for this request
|
|
510
509
|
# @param version [Wreq::Version, nil] HTTP version to use
|
|
510
|
+
# @param form [Hash{String=>String}, nil] Form data (application/x-www-form-urlencoded)
|
|
511
|
+
# @param json [Object, nil] JSON body (will be serialized)
|
|
512
|
+
# @param body [String, IO, nil] Raw request body (string or stream)
|
|
511
513
|
# @return [Wreq::Response] HTTP response
|
|
512
514
|
def patch(url, **options)
|
|
513
515
|
end
|
|
514
516
|
end
|
|
515
517
|
end
|
|
516
518
|
end
|
|
519
|
+
|
|
520
|
+
module Wreq
|
|
521
|
+
class Client
|
|
522
|
+
def inspect
|
|
523
|
+
"#<Wreq::Client>"
|
|
524
|
+
end
|
|
525
|
+
end
|
|
526
|
+
end
|
data/lib/wreq_ruby/cookie.rb
CHANGED
|
@@ -114,18 +114,11 @@ unless defined?(Wreq)
|
|
|
114
114
|
def get_all
|
|
115
115
|
end
|
|
116
116
|
|
|
117
|
-
# Add a cookie object for the given URL.
|
|
118
|
-
# @param cookie [Wreq::Cookie]
|
|
119
|
-
# @param url [String]
|
|
120
|
-
# @return [void]
|
|
121
|
-
def add_cookie(cookie, url)
|
|
122
|
-
end
|
|
123
|
-
|
|
124
117
|
# Add a cookie from a Set-Cookie string for the given URL.
|
|
125
|
-
# @param cookie [String] A Set-Cookie string
|
|
118
|
+
# @param cookie [String, Wreq::Cookie] A Set-Cookie string
|
|
126
119
|
# @param url [String]
|
|
127
120
|
# @return [void]
|
|
128
|
-
def
|
|
121
|
+
def add(cookie, url)
|
|
129
122
|
end
|
|
130
123
|
|
|
131
124
|
# Remove a cookie by name for the given URL.
|
|
@@ -142,3 +135,22 @@ unless defined?(Wreq)
|
|
|
142
135
|
end
|
|
143
136
|
end
|
|
144
137
|
end
|
|
138
|
+
|
|
139
|
+
module Wreq
|
|
140
|
+
class Cookie
|
|
141
|
+
def inspect
|
|
142
|
+
parts = ["#<Wreq::Cookie", name]
|
|
143
|
+
parts << "domain=#{domain}" if domain
|
|
144
|
+
parts << "path=#{path}" if path
|
|
145
|
+
parts << "secure" if secure?
|
|
146
|
+
parts << "http_only" if http_only?
|
|
147
|
+
parts.join(" ") + ">"
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
class Jar
|
|
152
|
+
def inspect
|
|
153
|
+
"#<Wreq::Jar [#{get_all.length} cookies]>"
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Wreq
|
|
4
|
-
#
|
|
4
|
+
# Browser and client fingerprint profile enumeration backed by Rust.
|
|
5
5
|
#
|
|
6
6
|
# Variants are exposed as constants under this class.
|
|
7
|
-
# Each constant is an instance of {Wreq::
|
|
7
|
+
# Each constant is an instance of {Wreq::Profile} and can be passed to
|
|
8
|
+
# {Wreq::Emulation.new} via the `profile:` keyword.
|
|
8
9
|
#
|
|
9
|
-
# @example Using predefined
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
|
|
10
|
+
# @example Using a predefined profile
|
|
11
|
+
# profile = Wreq::Profile::Chrome117
|
|
12
|
+
# profile.class #=> Wreq::Profile
|
|
13
|
+
#
|
|
14
|
+
# @example Applying a profile to emulation
|
|
15
|
+
# emu = Wreq::Emulation.new(profile: Wreq::Profile::Chrome117)
|
|
16
|
+
class Profile
|
|
13
17
|
# Constants are set by the native extension at initialization.
|
|
14
18
|
# These stubs are for documentation only.
|
|
15
19
|
unless const_defined?(:Chrome100)
|
|
@@ -52,6 +56,8 @@ module Wreq
|
|
|
52
56
|
Chrome145 = nil
|
|
53
57
|
Chrome146 = nil
|
|
54
58
|
Chrome147 = nil
|
|
59
|
+
Chrome148 = nil
|
|
60
|
+
|
|
55
61
|
Edge101 = nil
|
|
56
62
|
Edge122 = nil
|
|
57
63
|
Edge127 = nil
|
|
@@ -70,6 +76,8 @@ module Wreq
|
|
|
70
76
|
Edge145 = nil
|
|
71
77
|
Edge146 = nil
|
|
72
78
|
Edge147 = nil
|
|
79
|
+
Edge148 = nil
|
|
80
|
+
|
|
73
81
|
Firefox109 = nil
|
|
74
82
|
Firefox117 = nil
|
|
75
83
|
Firefox128 = nil
|
|
@@ -88,6 +96,9 @@ module Wreq
|
|
|
88
96
|
Firefox147 = nil
|
|
89
97
|
Firefox148 = nil
|
|
90
98
|
Firefox149 = nil
|
|
99
|
+
Firefox150 = nil
|
|
100
|
+
Firefox151 = nil
|
|
101
|
+
|
|
91
102
|
SafariIos17_2 = nil
|
|
92
103
|
SafariIos17_4_1 = nil
|
|
93
104
|
SafariIos16_5 = nil
|
|
@@ -111,10 +122,13 @@ module Wreq
|
|
|
111
122
|
Safari26 = nil
|
|
112
123
|
Safari26_1 = nil
|
|
113
124
|
Safari26_2 = nil
|
|
125
|
+
Safari26_3 = nil
|
|
126
|
+
Safari26_4 = nil
|
|
114
127
|
SafariIos26 = nil
|
|
115
128
|
SafariIos26_2 = nil
|
|
116
129
|
SafariIPad26 = nil
|
|
117
130
|
SafariIpad26_2 = nil
|
|
131
|
+
|
|
118
132
|
OkHttp3_9 = nil
|
|
119
133
|
OkHttp3_11 = nil
|
|
120
134
|
OkHttp3_13 = nil
|
|
@@ -123,6 +137,7 @@ module Wreq
|
|
|
123
137
|
OkHttp4_10 = nil
|
|
124
138
|
OkHttp4_12 = nil
|
|
125
139
|
OkHttp5 = nil
|
|
140
|
+
|
|
126
141
|
Opera116 = nil
|
|
127
142
|
Opera117 = nil
|
|
128
143
|
Opera118 = nil
|
|
@@ -138,25 +153,30 @@ module Wreq
|
|
|
138
153
|
Opera128 = nil
|
|
139
154
|
Opera129 = nil
|
|
140
155
|
Opera130 = nil
|
|
156
|
+
Opera131 = nils
|
|
141
157
|
end
|
|
142
158
|
|
|
143
159
|
unless method_defined?(:to_s)
|
|
144
|
-
# Returns
|
|
145
|
-
# @return [String]
|
|
160
|
+
# Returns the profile name.
|
|
161
|
+
# @return [String] Profile name as a string
|
|
146
162
|
def to_s
|
|
147
163
|
end
|
|
148
164
|
end
|
|
149
165
|
end
|
|
150
166
|
|
|
151
|
-
# Operating system
|
|
167
|
+
# Operating system platform enumeration backed by Rust.
|
|
152
168
|
#
|
|
153
169
|
# Variants are exposed as constants under this class.
|
|
154
|
-
# Each constant is an instance of {Wreq::
|
|
170
|
+
# Each constant is an instance of {Wreq::Platform} and can be passed to
|
|
171
|
+
# {Wreq::Emulation.new} via the `platform:` keyword.
|
|
155
172
|
#
|
|
156
|
-
# @example Using predefined
|
|
157
|
-
#
|
|
158
|
-
#
|
|
159
|
-
|
|
173
|
+
# @example Using a predefined platform
|
|
174
|
+
# platform = Wreq::Platform::Windows
|
|
175
|
+
# platform.class #=> Wreq::Platform
|
|
176
|
+
#
|
|
177
|
+
# @example Applying a platform to emulation
|
|
178
|
+
# emu = Wreq::Emulation.new(platform: Wreq::Platform::Windows)
|
|
179
|
+
class Platform
|
|
160
180
|
# Constants are set by the native extension at initialization.
|
|
161
181
|
# These stubs are for documentation only.
|
|
162
182
|
unless const_defined?(:Windows)
|
|
@@ -168,8 +188,8 @@ module Wreq
|
|
|
168
188
|
end
|
|
169
189
|
|
|
170
190
|
unless method_defined?(:to_s)
|
|
171
|
-
# Returns
|
|
172
|
-
# @return [String]
|
|
191
|
+
# Returns the platform name.
|
|
192
|
+
# @return [String] Platform name as a string
|
|
173
193
|
def to_s
|
|
174
194
|
end
|
|
175
195
|
end
|
|
@@ -177,26 +197,34 @@ module Wreq
|
|
|
177
197
|
|
|
178
198
|
# Emulation option wrapper.
|
|
179
199
|
#
|
|
180
|
-
# This class
|
|
181
|
-
#
|
|
182
|
-
#
|
|
200
|
+
# This class combines a fingerprint `profile`, an OS `platform`, and toggles
|
|
201
|
+
# for HTTP/2 and automatic default headers. The actual implementation is
|
|
202
|
+
# provided by Rust.
|
|
203
|
+
#
|
|
204
|
+
# `profile:` defaults to the library's default profile when omitted.
|
|
205
|
+
# `platform:` defaults to the library's default platform when omitted.
|
|
183
206
|
#
|
|
184
207
|
# @example Create an emulation option
|
|
185
|
-
# emu = Wreq::Emulation.new(
|
|
208
|
+
# emu = Wreq::Emulation.new(
|
|
209
|
+
# profile: Wreq::Profile::Chrome117,
|
|
210
|
+
# platform: Wreq::Platform::Windows,
|
|
211
|
+
# http2: true,
|
|
212
|
+
# headers: true
|
|
213
|
+
# )
|
|
186
214
|
#
|
|
187
|
-
# @param
|
|
188
|
-
# @param
|
|
189
|
-
# @param
|
|
190
|
-
# @param
|
|
215
|
+
# @param profile [Wreq::Profile, nil] Fingerprint profile to emulate
|
|
216
|
+
# @param platform [Wreq::Platform, nil] Operating system platform to emulate
|
|
217
|
+
# @param http2 [Boolean] Whether HTTP/2 support is enabled
|
|
218
|
+
# @param headers [Boolean] Whether default emulation headers are enabled
|
|
191
219
|
class Emulation
|
|
192
220
|
# Native fields and methods are set by the extension.
|
|
193
221
|
# This stub is for documentation only.
|
|
194
222
|
unless method_defined?(:new)
|
|
195
|
-
# @param
|
|
196
|
-
# @param
|
|
197
|
-
# @param
|
|
198
|
-
# @param
|
|
199
|
-
def self.new(
|
|
223
|
+
# @param profile [Wreq::Profile, nil] Fingerprint profile to emulate
|
|
224
|
+
# @param platform [Wreq::Platform, nil] Operating system platform to emulate
|
|
225
|
+
# @param http2 [Boolean] Whether HTTP/2 support is enabled
|
|
226
|
+
# @param headers [Boolean] Whether default emulation headers are enabled
|
|
227
|
+
def self.new(profile: nil, platform: nil, http2: true, headers: true)
|
|
200
228
|
end
|
|
201
229
|
end
|
|
202
230
|
end
|
data/lib/wreq_ruby/header.rb
CHANGED
data/lib/wreq_ruby/http.rb
CHANGED
|
@@ -49,6 +49,20 @@ module Wreq
|
|
|
49
49
|
def to_s
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
|
+
|
|
53
|
+
# Compares HTTP versions by semantic value, not object identity.
|
|
54
|
+
#
|
|
55
|
+
# This method is implemented by the native extension.
|
|
56
|
+
# When comparing with non-{Wreq::Version} objects, it returns false.
|
|
57
|
+
#
|
|
58
|
+
# @param other [Object] object to compare against
|
|
59
|
+
# @return [Boolean] true when both represent the same HTTP version
|
|
60
|
+
# @example
|
|
61
|
+
# Wreq::Version::HTTP_11 == response.version
|
|
62
|
+
unless method_defined?(:==)
|
|
63
|
+
def ==(other)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
52
66
|
end
|
|
53
67
|
|
|
54
68
|
# HTTP status code wrapper.
|
|
@@ -130,3 +144,17 @@ module Wreq
|
|
|
130
144
|
end
|
|
131
145
|
end
|
|
132
146
|
end
|
|
147
|
+
|
|
148
|
+
module Wreq
|
|
149
|
+
class StatusCode
|
|
150
|
+
def inspect
|
|
151
|
+
"#<Wreq::StatusCode #{self}>"
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
class Version
|
|
156
|
+
def inspect
|
|
157
|
+
"#<Wreq::Version #{self}>"
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|