wreq 1.2.4 → 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 +22 -19
- data/Cargo.toml +15 -2
- data/crates/wreq-util/.github/FUNDING.yml +15 -0
- data/crates/wreq-util/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- data/crates/wreq-util/.github/ISSUE_TEMPLATE/custom.md +10 -0
- data/crates/wreq-util/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/crates/wreq-util/.github/dependabot.yml +22 -0
- data/crates/wreq-util/.github/workflows/ci.yml +82 -0
- data/crates/wreq-util/.github/workflows/release-plz.yml +52 -0
- data/crates/wreq-util/.gitignore +24 -0
- data/crates/wreq-util/CHANGELOG.md +74 -0
- data/crates/wreq-util/Cargo.toml +94 -0
- data/crates/wreq-util/LICENSE +201 -0
- data/crates/wreq-util/README.md +62 -0
- data/crates/wreq-util/examples/emulate.rs +39 -0
- data/crates/wreq-util/examples/tower_delay.rs +191 -0
- data/crates/wreq-util/release-plz.toml +2 -0
- data/crates/wreq-util/rustfmt.toml +5 -0
- data/crates/wreq-util/src/emulate/compress.rs +85 -0
- data/crates/wreq-util/src/emulate/macros.rs +372 -0
- data/crates/wreq-util/src/emulate/profile/chrome/header.rs +74 -0
- data/crates/wreq-util/src/emulate/profile/chrome/http2.rs +65 -0
- data/crates/wreq-util/src/emulate/profile/chrome/tls.rs +153 -0
- data/crates/wreq-util/src/emulate/profile/chrome.rs +2028 -0
- data/crates/wreq-util/src/emulate/profile/firefox/header.rs +37 -0
- data/crates/wreq-util/src/emulate/profile/firefox/http2.rs +113 -0
- data/crates/wreq-util/src/emulate/profile/firefox/tls.rs +253 -0
- data/crates/wreq-util/src/emulate/profile/firefox.rs +518 -0
- data/crates/wreq-util/src/emulate/profile/okhttp.rs +241 -0
- data/crates/wreq-util/src/emulate/profile/opera/header.rs +29 -0
- data/crates/wreq-util/src/emulate/profile/opera/http2.rs +50 -0
- data/crates/wreq-util/src/emulate/profile/opera/tls.rs +97 -0
- data/crates/wreq-util/src/emulate/profile/opera.rs +299 -0
- data/crates/wreq-util/src/emulate/profile/safari/header.rs +59 -0
- data/crates/wreq-util/src/emulate/profile/safari/http2.rs +116 -0
- data/crates/wreq-util/src/emulate/profile/safari/tls.rs +177 -0
- data/crates/wreq-util/src/emulate/profile/safari.rs +222 -0
- data/crates/wreq-util/src/emulate/profile.rs +47 -0
- data/crates/wreq-util/src/emulate.rs +369 -0
- data/crates/wreq-util/src/lib.rs +14 -0
- data/crates/wreq-util/src/rand.rs +24 -0
- data/crates/wreq-util/src/tower/delay/future.rs +43 -0
- data/crates/wreq-util/src/tower/delay/layer.rs +201 -0
- data/crates/wreq-util/src/tower/delay/service.rs +190 -0
- data/crates/wreq-util/src/tower/delay.rs +98 -0
- data/crates/wreq-util/src/tower.rs +7 -0
- data/crates/wreq-util/tests/client.rs +153 -0
- data/crates/wreq-util/tests/emulate_chrome.rs +270 -0
- data/crates/wreq-util/tests/emulate_firefox.rs +92 -0
- data/crates/wreq-util/tests/emulate_okhttp.rs +46 -0
- data/crates/wreq-util/tests/emulate_opera.rs +113 -0
- data/crates/wreq-util/tests/emulate_safari.rs +151 -0
- data/crates/wreq-util/tests/support/mod.rs +55 -0
- data/crates/wreq-util/tests/support/server.rs +232 -0
- data/examples/emulate_request.rb +1 -1
- data/lib/wreq.rb +72 -45
- data/lib/wreq_ruby/body.rb +30 -9
- data/lib/wreq_ruby/client.rb +88 -55
- data/lib/wreq_ruby/cookie.rb +81 -21
- data/lib/wreq_ruby/emulate.rb +77 -7
- data/lib/wreq_ruby/error.rb +5 -7
- data/lib/wreq_ruby/header.rb +205 -114
- data/lib/wreq_ruby/http.rb +74 -0
- data/lib/wreq_ruby/response.rb +31 -3
- 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 +86 -50
- data/src/error.rs +198 -45
- data/src/extractor.rs +16 -76
- data/src/header.rs +318 -130
- 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/header_test.rb +228 -192
- data/test/json_precision_test.rb +209 -0
- data/test/option_validation_test.rb +311 -0
- data/test/stream_test.rb +36 -0
- data/test/value_semantics_test.rb +238 -0
- metadata +77 -1
data/lib/wreq_ruby/cookie.rb
CHANGED
|
@@ -1,45 +1,77 @@
|
|
|
1
1
|
unless defined?(Wreq)
|
|
2
2
|
module Wreq
|
|
3
|
-
#
|
|
3
|
+
# SameSite values for HTTP cookies.
|
|
4
4
|
#
|
|
5
|
-
#
|
|
5
|
+
# The constant names match the native Rust variants.
|
|
6
|
+
# standard:disable Naming/ConstantName
|
|
6
7
|
class SameSite
|
|
7
|
-
# Lax same-site policy.
|
|
8
|
-
Strict = nil
|
|
9
8
|
# Strict same-site policy.
|
|
9
|
+
Strict = nil
|
|
10
|
+
# Lax same-site policy.
|
|
10
11
|
Lax = nil
|
|
11
12
|
# None same-site policy.
|
|
12
13
|
None = nil
|
|
14
|
+
|
|
15
|
+
# Returns the SameSite attribute name (e.g. "Strict", "Lax", "None").
|
|
16
|
+
# @return [String]
|
|
17
|
+
def to_s
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Returns the SameSite attribute as a lowercase symbol (e.g. :strict, :lax, :none).
|
|
21
|
+
# @return [Symbol]
|
|
22
|
+
def to_sym
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Value-based equality.
|
|
26
|
+
# @param other [Object]
|
|
27
|
+
# @return [Boolean]
|
|
28
|
+
def ==(other)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Strict equality for Hash key and Set member semantics.
|
|
32
|
+
# @param other [Object]
|
|
33
|
+
# @return [Boolean]
|
|
34
|
+
def eql?(other)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Hash value consistent with {#eql?} for use as Hash keys.
|
|
38
|
+
# @return [Integer]
|
|
39
|
+
def hash
|
|
40
|
+
end
|
|
13
41
|
end
|
|
42
|
+
# standard:enable Naming/ConstantName
|
|
14
43
|
|
|
15
|
-
# A single HTTP cookie.
|
|
44
|
+
# A single HTTP cookie backed by an immutable native value.
|
|
16
45
|
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
# Constructor accepts `name`, `value`, plus optional keyword arguments for
|
|
20
|
-
# other attributes.
|
|
46
|
+
# Cookie instances can be shared safely between threads. Pass optional
|
|
47
|
+
# attributes as keywords to {.new}.
|
|
21
48
|
class Cookie
|
|
22
|
-
#
|
|
49
|
+
# Creates a Cookie instance.
|
|
23
50
|
#
|
|
24
|
-
#
|
|
51
|
+
# The native extension defines `.new` directly instead of `#initialize`.
|
|
25
52
|
#
|
|
26
53
|
# @param name [String] Cookie name
|
|
27
54
|
# @param value [String] Cookie value
|
|
28
55
|
# @param options [Hash] Optional keyword arguments
|
|
29
56
|
# @option options [String] :domain Domain attribute
|
|
30
57
|
# @option options [String] :path Path attribute
|
|
31
|
-
# @option options [Integer] :max_age Max-Age in seconds
|
|
32
|
-
#
|
|
58
|
+
# @option options [Integer] :max_age Signed Max-Age in seconds.
|
|
59
|
+
# Zero or negative values expire the cookie immediately.
|
|
60
|
+
# @option options [Time, Numeric] :expires A Time or finite Unix timestamp in seconds
|
|
33
61
|
# @option options [Boolean] :http_only HttpOnly flag
|
|
34
62
|
# @option options [Boolean] :secure Secure flag
|
|
35
63
|
# @option options [Wreq::SameSite] :same_site SameSite attribute
|
|
36
64
|
# @return [Wreq::Cookie]
|
|
65
|
+
# @raise [ArgumentError] if an option is unknown or duplicated, or if :expires is not finite
|
|
66
|
+
# @raise [RangeError] if :max_age or :expires is outside the supported range
|
|
67
|
+
# @raise [TypeError] if an option has the wrong type
|
|
37
68
|
# @example
|
|
38
69
|
# c = Wreq::Cookie.new(
|
|
39
70
|
# "sid", "abc",
|
|
40
71
|
# domain: "example.com",
|
|
41
72
|
# path: "/",
|
|
42
73
|
# max_age: 3600,
|
|
74
|
+
# expires: Time.utc(2030, 1, 1),
|
|
43
75
|
# http_only: true,
|
|
44
76
|
# secure: true,
|
|
45
77
|
# same_site: Wreq::SameSite::Lax
|
|
@@ -85,6 +117,11 @@ unless defined?(Wreq)
|
|
|
85
117
|
def same_site_strict?
|
|
86
118
|
end
|
|
87
119
|
|
|
120
|
+
# Returns the SameSite setting, or nil if it was omitted.
|
|
121
|
+
# @return [Wreq::SameSite, nil]
|
|
122
|
+
def same_site
|
|
123
|
+
end
|
|
124
|
+
|
|
88
125
|
# @return [String, nil] Path attribute
|
|
89
126
|
def path
|
|
90
127
|
end
|
|
@@ -93,31 +130,50 @@ unless defined?(Wreq)
|
|
|
93
130
|
def domain
|
|
94
131
|
end
|
|
95
132
|
|
|
96
|
-
#
|
|
133
|
+
# Returns the signed Max-Age lifetime in seconds.
|
|
134
|
+
#
|
|
135
|
+
# Zero and negative values expire the cookie immediately.
|
|
136
|
+
# @return [Integer, nil]
|
|
97
137
|
def max_age
|
|
98
138
|
end
|
|
99
139
|
|
|
100
|
-
#
|
|
140
|
+
# Returns the expiration time in UTC.
|
|
141
|
+
# @return [Time, nil]
|
|
142
|
+
def expires_at
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Returns the expiration as a Unix timestamp with fractional seconds.
|
|
146
|
+
# The Float return value may lose precision for large timestamps.
|
|
147
|
+
# @deprecated Use {#expires_at}, which returns Time.
|
|
148
|
+
# @return [Float, nil]
|
|
101
149
|
def expires
|
|
102
150
|
end
|
|
151
|
+
|
|
152
|
+
# Returns the cookie formatted as a Set-Cookie value.
|
|
153
|
+
# @return [String]
|
|
154
|
+
def to_s
|
|
155
|
+
end
|
|
103
156
|
end
|
|
104
157
|
|
|
105
|
-
#
|
|
158
|
+
# Stores cookies for reuse across requests.
|
|
159
|
+
#
|
|
160
|
+
# Pass a Jar to Wreq::Client as `cookie_provider` to share its cookies.
|
|
106
161
|
class Jar
|
|
107
|
-
#
|
|
162
|
+
# Creates an empty cookie jar.
|
|
108
163
|
# @return [Wreq::Jar]
|
|
109
164
|
def self.new
|
|
110
165
|
end
|
|
111
166
|
|
|
112
|
-
#
|
|
167
|
+
# Returns all stored cookies.
|
|
113
168
|
# @return [Array<Wreq::Cookie>]
|
|
114
169
|
def get_all
|
|
115
170
|
end
|
|
116
171
|
|
|
117
|
-
#
|
|
118
|
-
# @param cookie [String, Wreq::Cookie]
|
|
119
|
-
# @param url [String]
|
|
172
|
+
# Adds a Cookie object or Set-Cookie string for the given URL.
|
|
173
|
+
# @param cookie [String, Wreq::Cookie] Cookie to store
|
|
174
|
+
# @param url [String] URL that scopes the cookie
|
|
120
175
|
# @return [void]
|
|
176
|
+
# @raise [TypeError] if cookie is neither a String nor Wreq::Cookie
|
|
121
177
|
def add(cookie, url)
|
|
122
178
|
end
|
|
123
179
|
|
|
@@ -138,6 +194,8 @@ end
|
|
|
138
194
|
|
|
139
195
|
module Wreq
|
|
140
196
|
class Cookie
|
|
197
|
+
# Returns a short representation for debugging.
|
|
198
|
+
# @return [String]
|
|
141
199
|
def inspect
|
|
142
200
|
parts = ["#<Wreq::Cookie", name]
|
|
143
201
|
parts << "domain=#{domain}" if domain
|
|
@@ -149,6 +207,8 @@ module Wreq
|
|
|
149
207
|
end
|
|
150
208
|
|
|
151
209
|
class Jar
|
|
210
|
+
# Returns a short representation with the number of stored cookies.
|
|
211
|
+
# @return [String]
|
|
152
212
|
def inspect
|
|
153
213
|
"#<Wreq::Jar [#{get_all.length} cookies]>"
|
|
154
214
|
end
|
data/lib/wreq_ruby/emulate.rb
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# Profile and platform constants mirror the native enum variant names.
|
|
4
|
+
# standard:disable Naming/ConstantName
|
|
5
|
+
|
|
3
6
|
module Wreq
|
|
4
7
|
# Browser and client fingerprint profile enumeration backed by Rust.
|
|
5
8
|
#
|
|
@@ -58,6 +61,7 @@ module Wreq
|
|
|
58
61
|
Chrome147 = nil
|
|
59
62
|
Chrome148 = nil
|
|
60
63
|
Chrome149 = nil
|
|
64
|
+
Chrome150 = nil
|
|
61
65
|
|
|
62
66
|
Edge101 = nil
|
|
63
67
|
Edge122 = nil
|
|
@@ -154,7 +158,7 @@ module Wreq
|
|
|
154
158
|
Opera128 = nil
|
|
155
159
|
Opera129 = nil
|
|
156
160
|
Opera130 = nil
|
|
157
|
-
Opera131 =
|
|
161
|
+
Opera131 = nil
|
|
158
162
|
end
|
|
159
163
|
|
|
160
164
|
unless method_defined?(:to_s)
|
|
@@ -163,6 +167,29 @@ module Wreq
|
|
|
163
167
|
def to_s
|
|
164
168
|
end
|
|
165
169
|
end
|
|
170
|
+
|
|
171
|
+
unless method_defined?(:==)
|
|
172
|
+
# Value-based equality.
|
|
173
|
+
# @param other [Object]
|
|
174
|
+
# @return [Boolean]
|
|
175
|
+
def ==(other)
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
unless method_defined?(:eql?)
|
|
180
|
+
# Strict equality for Hash key and Set member semantics.
|
|
181
|
+
# @param other [Object]
|
|
182
|
+
# @return [Boolean]
|
|
183
|
+
def eql?(other)
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
unless method_defined?(:hash)
|
|
188
|
+
# Hash value consistent with {#eql?} for use as Hash keys.
|
|
189
|
+
# @return [Integer]
|
|
190
|
+
def hash
|
|
191
|
+
end
|
|
192
|
+
end
|
|
166
193
|
end
|
|
167
194
|
|
|
168
195
|
# Operating system platform enumeration backed by Rust.
|
|
@@ -194,6 +221,36 @@ module Wreq
|
|
|
194
221
|
def to_s
|
|
195
222
|
end
|
|
196
223
|
end
|
|
224
|
+
|
|
225
|
+
unless method_defined?(:to_sym)
|
|
226
|
+
# Returns the platform as a lowercase symbol (e.g. :windows, :linux).
|
|
227
|
+
# @return [Symbol]
|
|
228
|
+
def to_sym
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
unless method_defined?(:==)
|
|
233
|
+
# Value-based equality.
|
|
234
|
+
# @param other [Object]
|
|
235
|
+
# @return [Boolean]
|
|
236
|
+
def ==(other)
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
unless method_defined?(:eql?)
|
|
241
|
+
# Strict equality for Hash key and Set member semantics.
|
|
242
|
+
# @param other [Object]
|
|
243
|
+
# @return [Boolean]
|
|
244
|
+
def eql?(other)
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
unless method_defined?(:hash)
|
|
249
|
+
# Hash value consistent with {#eql?} for use as Hash keys.
|
|
250
|
+
# @return [Integer]
|
|
251
|
+
def hash
|
|
252
|
+
end
|
|
253
|
+
end
|
|
197
254
|
end
|
|
198
255
|
|
|
199
256
|
# Emulation option wrapper.
|
|
@@ -215,18 +272,31 @@ module Wreq
|
|
|
215
272
|
#
|
|
216
273
|
# @param profile [Wreq::Profile, nil] Fingerprint profile to emulate
|
|
217
274
|
# @param platform [Wreq::Platform, nil] Operating system platform to emulate
|
|
218
|
-
# @param http2 [Boolean] Whether HTTP/2
|
|
219
|
-
#
|
|
275
|
+
# @param http2 [Boolean, nil] Whether HTTP/2 emulation is enabled; defaults
|
|
276
|
+
# to true when omitted or nil
|
|
277
|
+
# @param headers [Boolean, nil] Whether default emulation headers are enabled;
|
|
278
|
+
# defaults to true when omitted or nil
|
|
279
|
+
# @return [Wreq::Emulation] Configured emulation settings
|
|
280
|
+
# @raise [ArgumentError] if an option is unknown or extra arguments are given
|
|
281
|
+
# @raise [TypeError] if the option argument is not a Hash or a value has the
|
|
282
|
+
# wrong Ruby type
|
|
220
283
|
class Emulation
|
|
221
284
|
# Native fields and methods are set by the extension.
|
|
222
285
|
# This stub is for documentation only.
|
|
223
|
-
unless
|
|
286
|
+
unless singleton_methods(false).include?(:new)
|
|
224
287
|
# @param profile [Wreq::Profile, nil] Fingerprint profile to emulate
|
|
225
288
|
# @param platform [Wreq::Platform, nil] Operating system platform to emulate
|
|
226
|
-
# @param http2 [Boolean] Whether HTTP/2
|
|
227
|
-
#
|
|
228
|
-
|
|
289
|
+
# @param http2 [Boolean, nil] Whether HTTP/2 emulation is enabled; defaults
|
|
290
|
+
# to true when omitted or nil
|
|
291
|
+
# @param headers [Boolean, nil] Whether default emulation headers are enabled;
|
|
292
|
+
# defaults to true when omitted or nil
|
|
293
|
+
# @return [Wreq::Emulation] Configured emulation settings
|
|
294
|
+
# @raise [ArgumentError] if an option is unknown or extra arguments are given
|
|
295
|
+
# @raise [TypeError] if an option or value has the wrong Ruby type
|
|
296
|
+
def self.new(**options)
|
|
229
297
|
end
|
|
230
298
|
end
|
|
231
299
|
end
|
|
232
300
|
end
|
|
301
|
+
|
|
302
|
+
# standard:enable Naming/ConstantName
|
data/lib/wreq_ruby/error.rb
CHANGED
|
@@ -88,7 +88,7 @@ unless defined?(Wreq)
|
|
|
88
88
|
#
|
|
89
89
|
# @example
|
|
90
90
|
# begin
|
|
91
|
-
# client = Wreq::Client.new(max_redirects: 3)
|
|
91
|
+
# client = Wreq::Client.new(allow_redirects: true, max_redirects: 3)
|
|
92
92
|
# client.get("https://httpbin.io/redirect/10")
|
|
93
93
|
# rescue Wreq::RedirectError => e
|
|
94
94
|
# puts "Too many redirects: #{e.message}"
|
|
@@ -139,16 +139,14 @@ unless defined?(Wreq)
|
|
|
139
139
|
|
|
140
140
|
# Configuration and builder errors
|
|
141
141
|
|
|
142
|
-
#
|
|
142
|
+
# A native client or request configuration could not be built.
|
|
143
143
|
#
|
|
144
|
-
# Raised when
|
|
144
|
+
# Raised when validated Ruby options cannot be represented by the native
|
|
145
|
+
# builder or request body.
|
|
145
146
|
#
|
|
146
147
|
# @example
|
|
147
148
|
# begin
|
|
148
|
-
# client = Wreq::Client.new(
|
|
149
|
-
# proxy: "invalid://proxy",
|
|
150
|
-
# timeout: -1
|
|
151
|
-
# )
|
|
149
|
+
# client = Wreq::Client.new(proxy: "invalid://")
|
|
152
150
|
# rescue Wreq::BuilderError => e
|
|
153
151
|
# puts "Invalid configuration: #{e.message}"
|
|
154
152
|
# end
|