wreq 1.2.3-x64-mingw-ucrt

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.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/Cargo.lock +1687 -0
  3. data/Cargo.toml +54 -0
  4. data/Gemfile +18 -0
  5. data/LICENSE +201 -0
  6. data/README.md +153 -0
  7. data/Rakefile +90 -0
  8. data/build.rs +16 -0
  9. data/docs/windows-gnu-tokio-crash.md +70 -0
  10. data/examples/body.rb +42 -0
  11. data/examples/client.rb +33 -0
  12. data/examples/cookie.rb +24 -0
  13. data/examples/emulate_request.rb +37 -0
  14. data/examples/headers.rb +27 -0
  15. data/examples/proxy.rb +113 -0
  16. data/examples/send_stream.rb +85 -0
  17. data/examples/stream.rb +14 -0
  18. data/examples/thread_interrupt.rb +83 -0
  19. data/extconf.rb +7 -0
  20. data/lib/wreq.rb +303 -0
  21. data/lib/wreq_ruby/3.3/wreq_ruby.so +0 -0
  22. data/lib/wreq_ruby/3.4/wreq_ruby.so +0 -0
  23. data/lib/wreq_ruby/4.0/wreq_ruby.so +0 -0
  24. data/lib/wreq_ruby/body.rb +36 -0
  25. data/lib/wreq_ruby/client.rb +526 -0
  26. data/lib/wreq_ruby/cookie.rb +156 -0
  27. data/lib/wreq_ruby/emulate.rb +232 -0
  28. data/lib/wreq_ruby/error.rb +157 -0
  29. data/lib/wreq_ruby/header.rb +205 -0
  30. data/lib/wreq_ruby/http.rb +160 -0
  31. data/lib/wreq_ruby/response.rb +209 -0
  32. data/script/build_platform_gem.rb +34 -0
  33. data/script/build_windows_gnu.ps1 +257 -0
  34. data/src/arch.rs +33 -0
  35. data/src/client/body/form.rs +2 -0
  36. data/src/client/body/json.rs +16 -0
  37. data/src/client/body/stream.rs +146 -0
  38. data/src/client/body.rs +57 -0
  39. data/src/client/param.rs +19 -0
  40. data/src/client/query.rs +2 -0
  41. data/src/client/req.rs +274 -0
  42. data/src/client/resp.rs +248 -0
  43. data/src/client.rs +413 -0
  44. data/src/cookie.rs +312 -0
  45. data/src/emulate.rs +376 -0
  46. data/src/error.rs +163 -0
  47. data/src/extractor.rs +117 -0
  48. data/src/gvl.rs +154 -0
  49. data/src/header.rs +245 -0
  50. data/src/http.rs +142 -0
  51. data/src/lib.rs +98 -0
  52. data/src/macros.rs +123 -0
  53. data/src/rt.rs +46 -0
  54. data/test/client_cookie_test.rb +46 -0
  55. data/test/client_test.rb +136 -0
  56. data/test/cookie_test.rb +182 -0
  57. data/test/emulation_test.rb +21 -0
  58. data/test/error_handling_test.rb +92 -0
  59. data/test/header_test.rb +290 -0
  60. data/test/inspect_test.rb +125 -0
  61. data/test/module_methods_test.rb +75 -0
  62. data/test/orig_header_test.rb +115 -0
  63. data/test/request_parameters_test.rb +175 -0
  64. data/test/request_test.rb +244 -0
  65. data/test/response_test.rb +69 -0
  66. data/test/stream_test.rb +397 -0
  67. data/test/test_helper.rb +52 -0
  68. data/wreq.gemspec +68 -0
  69. metadata +123 -0
@@ -0,0 +1,156 @@
1
+ unless defined?(Wreq)
2
+ module Wreq
3
+ # Cookie SameSite attribute.
4
+ #
5
+ # Values follow the Rust enum exposed by the native extension.
6
+ class SameSite
7
+ # Lax same-site policy.
8
+ Strict = nil
9
+ # Strict same-site policy.
10
+ Lax = nil
11
+ # None same-site policy.
12
+ None = nil
13
+ end
14
+
15
+ # A single HTTP cookie.
16
+ #
17
+ # Thread-safe: instances are backed by an immutable Rust value and can be
18
+ # shared across threads safely. This mirrors the native `Wreq::Cookie`.
19
+ # Constructor accepts `name`, `value`, plus optional keyword arguments for
20
+ # other attributes.
21
+ class Cookie
22
+ # Create a new Cookie instance.
23
+ #
24
+ # Note: This matches the native binding which defines `new` (not `initialize`).
25
+ #
26
+ # @param name [String] Cookie name
27
+ # @param value [String] Cookie value
28
+ # @param options [Hash] Optional keyword arguments
29
+ # @option options [String] :domain Domain attribute
30
+ # @option options [String] :path Path attribute
31
+ # @option options [Integer] :max_age Max-Age in seconds
32
+ # @option options [Float] :expires Unix timestamp (seconds, float)
33
+ # @option options [Boolean] :http_only HttpOnly flag
34
+ # @option options [Boolean] :secure Secure flag
35
+ # @option options [Wreq::SameSite] :same_site SameSite attribute
36
+ # @return [Wreq::Cookie]
37
+ # @example
38
+ # c = Wreq::Cookie.new(
39
+ # "sid", "abc",
40
+ # domain: "example.com",
41
+ # path: "/",
42
+ # max_age: 3600,
43
+ # http_only: true,
44
+ # secure: true,
45
+ # same_site: Wreq::SameSite::Lax
46
+ # )
47
+ def self.new(name, value, **options)
48
+ end
49
+
50
+ # @return [String] Cookie name
51
+ def name
52
+ end
53
+
54
+ # @return [String] Cookie value
55
+ def value
56
+ end
57
+
58
+ # Returns true if the HttpOnly directive is enabled.
59
+ # @return [Boolean]
60
+ def http_only
61
+ end
62
+
63
+ # Predicate version of http_only.
64
+ # @return [Boolean]
65
+ def http_only?
66
+ end
67
+
68
+ # Returns true if the Secure directive is enabled.
69
+ # @return [Boolean]
70
+ def secure
71
+ end
72
+
73
+ # Predicate version of secure.
74
+ # @return [Boolean]
75
+ def secure?
76
+ end
77
+
78
+ # Returns true if SameSite is Lax.
79
+ # @return [Boolean]
80
+ def same_site_lax?
81
+ end
82
+
83
+ # Returns true if SameSite is Strict.
84
+ # @return [Boolean]
85
+ def same_site_strict?
86
+ end
87
+
88
+ # @return [String, nil] Path attribute
89
+ def path
90
+ end
91
+
92
+ # @return [String, nil] Domain attribute
93
+ def domain
94
+ end
95
+
96
+ # @return [Integer, nil] Max-Age in seconds
97
+ def max_age
98
+ end
99
+
100
+ # @return [Float, nil] Expires as Unix timestamp (seconds)
101
+ def expires
102
+ end
103
+ end
104
+
105
+ # A cookie store (jar) used by the client to manage cookies across requests.
106
+ class Jar
107
+ # Create a new, empty cookie jar.
108
+ # @return [Wreq::Jar]
109
+ def self.new
110
+ end
111
+
112
+ # Get all cookies currently stored.
113
+ # @return [Array<Wreq::Cookie>]
114
+ def get_all
115
+ end
116
+
117
+ # Add a cookie from a Set-Cookie string for the given URL.
118
+ # @param cookie [String, Wreq::Cookie] A Set-Cookie string
119
+ # @param url [String]
120
+ # @return [void]
121
+ def add(cookie, url)
122
+ end
123
+
124
+ # Remove a cookie by name for the given URL.
125
+ # @param name [String]
126
+ # @param url [String]
127
+ # @return [void]
128
+ def remove(name, url)
129
+ end
130
+
131
+ # Clear all cookies from the jar.
132
+ # @return [void]
133
+ def clear
134
+ end
135
+ end
136
+ end
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
@@ -0,0 +1,232 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Wreq
4
+ # Browser and client fingerprint profile enumeration backed by Rust.
5
+ #
6
+ # Variants are exposed as constants under this class.
7
+ # Each constant is an instance of {Wreq::Profile} and can be passed to
8
+ # {Wreq::Emulation.new} via the `profile:` keyword.
9
+ #
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
17
+ # Constants are set by the native extension at initialization.
18
+ # These stubs are for documentation only.
19
+ unless const_defined?(:Chrome100)
20
+ Chrome100 = nil
21
+ Chrome101 = nil
22
+ Chrome104 = nil
23
+ Chrome105 = nil
24
+ Chrome106 = nil
25
+ Chrome107 = nil
26
+ Chrome108 = nil
27
+ Chrome109 = nil
28
+ Chrome110 = nil
29
+ Chrome114 = nil
30
+ Chrome116 = nil
31
+ Chrome117 = nil
32
+ Chrome118 = nil
33
+ Chrome119 = nil
34
+ Chrome120 = nil
35
+ Chrome123 = nil
36
+ Chrome124 = nil
37
+ Chrome126 = nil
38
+ Chrome127 = nil
39
+ Chrome128 = nil
40
+ Chrome129 = nil
41
+ Chrome130 = nil
42
+ Chrome131 = nil
43
+ Chrome132 = nil
44
+ Chrome133 = nil
45
+ Chrome134 = nil
46
+ Chrome135 = nil
47
+ Chrome136 = nil
48
+ Chrome137 = nil
49
+ Chrome138 = nil
50
+ Chrome139 = nil
51
+ Chrome140 = nil
52
+ Chrome141 = nil
53
+ Chrome142 = nil
54
+ Chrome143 = nil
55
+ Chrome144 = nil
56
+ Chrome145 = nil
57
+ Chrome146 = nil
58
+ Chrome147 = nil
59
+ Chrome148 = nil
60
+ Chrome149 = nil
61
+
62
+ Edge101 = nil
63
+ Edge122 = nil
64
+ Edge127 = nil
65
+ Edge131 = nil
66
+ Edge134 = nil
67
+ Edge135 = nil
68
+ Edge136 = nil
69
+ Edge137 = nil
70
+ Edge138 = nil
71
+ Edge139 = nil
72
+ Edge140 = nil
73
+ Edge141 = nil
74
+ Edge142 = nil
75
+ Edge143 = nil
76
+ Edge144 = nil
77
+ Edge145 = nil
78
+ Edge146 = nil
79
+ Edge147 = nil
80
+ Edge148 = nil
81
+
82
+ Firefox109 = nil
83
+ Firefox117 = nil
84
+ Firefox128 = nil
85
+ Firefox133 = nil
86
+ Firefox135 = nil
87
+ FirefoxPrivate135 = nil
88
+ FirefoxAndroid135 = nil
89
+ Firefox136 = nil
90
+ FirefoxPrivate136 = nil
91
+ Firefox139 = nil
92
+ Firefox142 = nil
93
+ Firefox143 = nil
94
+ Firefox144 = nil
95
+ Firefox145 = nil
96
+ Firefox146 = nil
97
+ Firefox147 = nil
98
+ Firefox148 = nil
99
+ Firefox149 = nil
100
+ Firefox150 = nil
101
+ Firefox151 = nil
102
+
103
+ SafariIos17_2 = nil
104
+ SafariIos17_4_1 = nil
105
+ SafariIos16_5 = nil
106
+ Safari15_3 = nil
107
+ Safari15_5 = nil
108
+ Safari15_6_1 = nil
109
+ Safari16 = nil
110
+ Safari16_5 = nil
111
+ Safari17_0 = nil
112
+ Safari17_2_1 = nil
113
+ Safari17_4_1 = nil
114
+ Safari17_5 = nil
115
+ Safari17_6 = nil
116
+ Safari18 = nil
117
+ SafariIPad18 = nil
118
+ Safari18_2 = nil
119
+ Safari18_3 = nil
120
+ Safari18_3_1 = nil
121
+ SafariIos18_1_1 = nil
122
+ Safari18_5 = nil
123
+ Safari26 = nil
124
+ Safari26_1 = nil
125
+ Safari26_2 = nil
126
+ Safari26_3 = nil
127
+ Safari26_4 = nil
128
+ SafariIos26 = nil
129
+ SafariIos26_2 = nil
130
+ SafariIPad26 = nil
131
+ SafariIpad26_2 = nil
132
+
133
+ OkHttp3_9 = nil
134
+ OkHttp3_11 = nil
135
+ OkHttp3_13 = nil
136
+ OkHttp3_14 = nil
137
+ OkHttp4_9 = nil
138
+ OkHttp4_10 = nil
139
+ OkHttp4_12 = nil
140
+ OkHttp5 = nil
141
+
142
+ Opera116 = nil
143
+ Opera117 = nil
144
+ Opera118 = nil
145
+ Opera119 = nil
146
+ Opera120 = nil
147
+ Opera121 = nil
148
+ Opera122 = nil
149
+ Opera123 = nil
150
+ Opera124 = nil
151
+ Opera125 = nil
152
+ Opera126 = nil
153
+ Opera127 = nil
154
+ Opera128 = nil
155
+ Opera129 = nil
156
+ Opera130 = nil
157
+ Opera131 = nils
158
+ end
159
+
160
+ unless method_defined?(:to_s)
161
+ # Returns the profile name.
162
+ # @return [String] Profile name as a string
163
+ def to_s
164
+ end
165
+ end
166
+ end
167
+
168
+ # Operating system platform enumeration backed by Rust.
169
+ #
170
+ # Variants are exposed as constants under this class.
171
+ # Each constant is an instance of {Wreq::Platform} and can be passed to
172
+ # {Wreq::Emulation.new} via the `platform:` keyword.
173
+ #
174
+ # @example Using a predefined platform
175
+ # platform = Wreq::Platform::Windows
176
+ # platform.class #=> Wreq::Platform
177
+ #
178
+ # @example Applying a platform to emulation
179
+ # emu = Wreq::Emulation.new(platform: Wreq::Platform::Windows)
180
+ class Platform
181
+ # Constants are set by the native extension at initialization.
182
+ # These stubs are for documentation only.
183
+ unless const_defined?(:Windows)
184
+ Windows = nil
185
+ MacOS = nil
186
+ Linux = nil
187
+ Android = nil
188
+ IOS = nil
189
+ end
190
+
191
+ unless method_defined?(:to_s)
192
+ # Returns the platform name.
193
+ # @return [String] Platform name as a string
194
+ def to_s
195
+ end
196
+ end
197
+ end
198
+
199
+ # Emulation option wrapper.
200
+ #
201
+ # This class combines a fingerprint `profile`, an OS `platform`, and toggles
202
+ # for HTTP/2 and automatic default headers. The actual implementation is
203
+ # provided by Rust.
204
+ #
205
+ # `profile:` defaults to the library's default profile when omitted.
206
+ # `platform:` defaults to the library's default platform when omitted.
207
+ #
208
+ # @example Create an emulation option
209
+ # emu = Wreq::Emulation.new(
210
+ # profile: Wreq::Profile::Chrome117,
211
+ # platform: Wreq::Platform::Windows,
212
+ # http2: true,
213
+ # headers: true
214
+ # )
215
+ #
216
+ # @param profile [Wreq::Profile, nil] Fingerprint profile to emulate
217
+ # @param platform [Wreq::Platform, nil] Operating system platform to emulate
218
+ # @param http2 [Boolean] Whether HTTP/2 support is enabled
219
+ # @param headers [Boolean] Whether default emulation headers are enabled
220
+ class Emulation
221
+ # Native fields and methods are set by the extension.
222
+ # This stub is for documentation only.
223
+ unless method_defined?(:new)
224
+ # @param profile [Wreq::Profile, nil] Fingerprint profile to emulate
225
+ # @param platform [Wreq::Platform, nil] Operating system platform to emulate
226
+ # @param http2 [Boolean] Whether HTTP/2 support is enabled
227
+ # @param headers [Boolean] Whether default emulation headers are enabled
228
+ def self.new(profile: nil, platform: nil, http2: true, headers: true)
229
+ end
230
+ end
231
+ end
232
+ end
@@ -0,0 +1,157 @@
1
+ # frozen_string_literal: true
2
+
3
+ unless defined?(Wreq)
4
+ module Wreq
5
+ # System-level and runtime errors
6
+
7
+ # Memory allocation failed.
8
+ class MemoryError < StandardError; end
9
+
10
+ # Network connection errors
11
+
12
+ # Connection to the server failed.
13
+ #
14
+ # Raised when the client cannot establish a connection to the server.
15
+ #
16
+ # @example
17
+ # begin
18
+ # client.get("http://localhost:9999")
19
+ # rescue Wreq::ConnectionError => e
20
+ # puts "Connection failed: #{e.message}"
21
+ # retry_with_backoff
22
+ # end
23
+ class ConnectionError < StandardError; end
24
+
25
+ # Proxy Connection to the server failed.
26
+ #
27
+ # Raised when the client cannot establish a connection to the proxy server.
28
+ # @example
29
+ # begin
30
+ # client.get("http://example.com", proxy: "http://invalid-proxy:8080")
31
+ # rescue Wreq::ProxyConnectionError => e
32
+ # puts "Proxy connection failed: #{e.message}"
33
+ # retry_with_different_proxy
34
+ # end
35
+ class ProxyConnectionError < StandardError; end
36
+
37
+ # Connection was reset by the server.
38
+ #
39
+ # Raised when the server closes the connection unexpectedly.
40
+ #
41
+ # @example
42
+ # rescue Wreq::ConnectionResetError => e
43
+ # puts "Connection reset: #{e.message}"
44
+ # end
45
+ class ConnectionResetError < StandardError; end
46
+
47
+ # TLS/SSL error occurred.
48
+ #
49
+ # Raised when there's an error with TLS/SSL, such as certificate
50
+ # verification failure or protocol mismatch.
51
+ #
52
+ # @example
53
+ # begin
54
+ # client.get("https://self-signed.badssl.com")
55
+ # rescue Wreq::TlsError => e
56
+ # puts "TLS error: #{e.message}"
57
+ # end
58
+ class TlsError < StandardError; end
59
+
60
+ # HTTP protocol and request/response errors
61
+
62
+ # Request failed.
63
+ #
64
+ # Generic error for request failures that don't fit other categories.
65
+ #
66
+ # @example
67
+ # rescue Wreq::RequestError => e
68
+ # puts "Request failed: #{e.message}"
69
+ # end
70
+ class RequestError < StandardError; end
71
+
72
+ # HTTP status code indicates an error.
73
+ #
74
+ # Raised when the server returns an error status code (4xx or 5xx).
75
+ #
76
+ # @example
77
+ # begin
78
+ # response = client.get("https://httpbin.io/status/404")
79
+ # rescue Wreq::StatusError => e
80
+ # puts "HTTP error: #{e.message}"
81
+ # # e.response contains the full response
82
+ # end
83
+ class StatusError < StandardError; end
84
+
85
+ # Redirect handling failed.
86
+ #
87
+ # Raised when too many redirects occur or redirect logic fails.
88
+ #
89
+ # @example
90
+ # begin
91
+ # client = Wreq::Client.new(max_redirects: 3)
92
+ # client.get("https://httpbin.io/redirect/10")
93
+ # rescue Wreq::RedirectError => e
94
+ # puts "Too many redirects: #{e.message}"
95
+ # end
96
+ class RedirectError < StandardError; end
97
+
98
+ # Request timed out.
99
+ #
100
+ # Raised when the request exceeds the configured timeout.
101
+ #
102
+ # @example
103
+ # begin
104
+ # client = Wreq::Client.new(timeout: 5)
105
+ # client.get("https://httpbin.io/delay/10")
106
+ # rescue Wreq::TimeoutError => e
107
+ # puts "Request timed out: #{e.message}"
108
+ # retry_with_longer_timeout
109
+ # end
110
+ class TimeoutError < StandardError; end
111
+
112
+ # Data processing and encoding errors
113
+
114
+ # Response body processing failed.
115
+ #
116
+ # Raised when there's an error reading or processing the response body.
117
+ #
118
+ # @example
119
+ # rescue Wreq::BodyError => e
120
+ # puts "Body error: #{e.message}"
121
+ # end
122
+ class BodyError < StandardError; end
123
+
124
+ # Decoding response failed.
125
+ #
126
+ # Raised when response content cannot be decoded (e.g., invalid UTF-8,
127
+ # malformed JSON, corrupted compression).
128
+ #
129
+ # @example
130
+ # begin
131
+ # response = client.get("https://example.com/invalid-utf8")
132
+ # response.text # May raise DecodingError
133
+ # rescue Wreq::DecodingError => e
134
+ # puts "Decoding error: #{e.message}"
135
+ # # Fall back to binary data
136
+ # data = response.body
137
+ # end
138
+ class DecodingError < StandardError; end
139
+
140
+ # Configuration and builder errors
141
+
142
+ # Client configuration is invalid.
143
+ #
144
+ # Raised when the client is configured with invalid options.
145
+ #
146
+ # @example
147
+ # begin
148
+ # client = Wreq::Client.new(
149
+ # proxy: "invalid://proxy",
150
+ # timeout: -1
151
+ # )
152
+ # rescue Wreq::BuilderError => e
153
+ # puts "Invalid configuration: #{e.message}"
154
+ # end
155
+ class BuilderError < StandardError; end
156
+ end
157
+ end