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.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/Cargo.lock +22 -19
  3. data/Cargo.toml +15 -2
  4. data/crates/wreq-util/.github/FUNDING.yml +15 -0
  5. data/crates/wreq-util/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  6. data/crates/wreq-util/.github/ISSUE_TEMPLATE/custom.md +10 -0
  7. data/crates/wreq-util/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  8. data/crates/wreq-util/.github/dependabot.yml +22 -0
  9. data/crates/wreq-util/.github/workflows/ci.yml +82 -0
  10. data/crates/wreq-util/.github/workflows/release-plz.yml +52 -0
  11. data/crates/wreq-util/.gitignore +24 -0
  12. data/crates/wreq-util/CHANGELOG.md +74 -0
  13. data/crates/wreq-util/Cargo.toml +94 -0
  14. data/crates/wreq-util/LICENSE +201 -0
  15. data/crates/wreq-util/README.md +62 -0
  16. data/crates/wreq-util/examples/emulate.rs +39 -0
  17. data/crates/wreq-util/examples/tower_delay.rs +191 -0
  18. data/crates/wreq-util/release-plz.toml +2 -0
  19. data/crates/wreq-util/rustfmt.toml +5 -0
  20. data/crates/wreq-util/src/emulate/compress.rs +85 -0
  21. data/crates/wreq-util/src/emulate/macros.rs +372 -0
  22. data/crates/wreq-util/src/emulate/profile/chrome/header.rs +74 -0
  23. data/crates/wreq-util/src/emulate/profile/chrome/http2.rs +65 -0
  24. data/crates/wreq-util/src/emulate/profile/chrome/tls.rs +153 -0
  25. data/crates/wreq-util/src/emulate/profile/chrome.rs +2028 -0
  26. data/crates/wreq-util/src/emulate/profile/firefox/header.rs +37 -0
  27. data/crates/wreq-util/src/emulate/profile/firefox/http2.rs +113 -0
  28. data/crates/wreq-util/src/emulate/profile/firefox/tls.rs +253 -0
  29. data/crates/wreq-util/src/emulate/profile/firefox.rs +518 -0
  30. data/crates/wreq-util/src/emulate/profile/okhttp.rs +241 -0
  31. data/crates/wreq-util/src/emulate/profile/opera/header.rs +29 -0
  32. data/crates/wreq-util/src/emulate/profile/opera/http2.rs +50 -0
  33. data/crates/wreq-util/src/emulate/profile/opera/tls.rs +97 -0
  34. data/crates/wreq-util/src/emulate/profile/opera.rs +299 -0
  35. data/crates/wreq-util/src/emulate/profile/safari/header.rs +59 -0
  36. data/crates/wreq-util/src/emulate/profile/safari/http2.rs +116 -0
  37. data/crates/wreq-util/src/emulate/profile/safari/tls.rs +177 -0
  38. data/crates/wreq-util/src/emulate/profile/safari.rs +222 -0
  39. data/crates/wreq-util/src/emulate/profile.rs +47 -0
  40. data/crates/wreq-util/src/emulate.rs +369 -0
  41. data/crates/wreq-util/src/lib.rs +14 -0
  42. data/crates/wreq-util/src/rand.rs +24 -0
  43. data/crates/wreq-util/src/tower/delay/future.rs +43 -0
  44. data/crates/wreq-util/src/tower/delay/layer.rs +201 -0
  45. data/crates/wreq-util/src/tower/delay/service.rs +190 -0
  46. data/crates/wreq-util/src/tower/delay.rs +98 -0
  47. data/crates/wreq-util/src/tower.rs +7 -0
  48. data/crates/wreq-util/tests/client.rs +153 -0
  49. data/crates/wreq-util/tests/emulate_chrome.rs +270 -0
  50. data/crates/wreq-util/tests/emulate_firefox.rs +92 -0
  51. data/crates/wreq-util/tests/emulate_okhttp.rs +46 -0
  52. data/crates/wreq-util/tests/emulate_opera.rs +113 -0
  53. data/crates/wreq-util/tests/emulate_safari.rs +151 -0
  54. data/crates/wreq-util/tests/support/mod.rs +55 -0
  55. data/crates/wreq-util/tests/support/server.rs +232 -0
  56. data/examples/emulate_request.rb +1 -1
  57. data/lib/wreq.rb +72 -45
  58. data/lib/wreq_ruby/body.rb +30 -9
  59. data/lib/wreq_ruby/client.rb +88 -55
  60. data/lib/wreq_ruby/cookie.rb +81 -21
  61. data/lib/wreq_ruby/emulate.rb +77 -7
  62. data/lib/wreq_ruby/error.rb +5 -7
  63. data/lib/wreq_ruby/header.rb +205 -114
  64. data/lib/wreq_ruby/http.rb +74 -0
  65. data/lib/wreq_ruby/response.rb +31 -3
  66. data/script/build_windows_gnu.ps1 +6 -0
  67. data/src/arch.rs +22 -0
  68. data/src/client/body/form.rs +2 -0
  69. data/src/client/body/json.rs +47 -14
  70. data/src/client/body/stream.rs +147 -43
  71. data/src/client/body.rs +11 -15
  72. data/src/client/param.rs +7 -7
  73. data/src/client/req.rs +87 -47
  74. data/src/client/resp.rs +23 -24
  75. data/src/client.rs +310 -230
  76. data/src/cookie.rs +280 -87
  77. data/src/emulate.rs +86 -50
  78. data/src/error.rs +198 -45
  79. data/src/extractor.rs +16 -76
  80. data/src/header.rs +318 -130
  81. data/src/http.rs +62 -33
  82. data/src/lib.rs +26 -20
  83. data/src/macros.rs +71 -46
  84. data/src/options.rs +284 -0
  85. data/src/rt.rs +22 -11
  86. data/src/serde/de/array_deserializer.rs +48 -0
  87. data/src/serde/de/array_enumerator.rs +59 -0
  88. data/src/serde/de/deserializer.rs +307 -0
  89. data/src/serde/de/enum_deserializer.rs +47 -0
  90. data/src/serde/de/hash_deserializer.rs +89 -0
  91. data/src/serde/de/number_deserializer.rs +51 -0
  92. data/src/serde/de/variant_deserializer.rs +101 -0
  93. data/src/serde/de.rs +33 -0
  94. data/src/serde/error.rs +146 -0
  95. data/src/serde/ser/enums.rs +14 -0
  96. data/src/serde/ser/map_serializer.rs +56 -0
  97. data/src/serde/ser/seq_serializer.rs +71 -0
  98. data/src/serde/ser/serializer.rs +194 -0
  99. data/src/serde/ser/struct_serializer.rs +106 -0
  100. data/src/serde/ser/struct_variant_serializer.rs +44 -0
  101. data/src/serde/ser/tuple_variant_serializer.rs +41 -0
  102. data/src/serde/ser.rs +18 -0
  103. data/src/serde/tests.rs +237 -0
  104. data/src/serde.rs +202 -0
  105. data/test/body_sender_test.rb +246 -0
  106. data/test/cookie_test.rb +211 -10
  107. data/test/header_test.rb +228 -192
  108. data/test/json_precision_test.rb +209 -0
  109. data/test/option_validation_test.rb +311 -0
  110. data/test/stream_test.rb +36 -0
  111. data/test/value_semantics_test.rb +238 -0
  112. metadata +77 -1
@@ -0,0 +1,238 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class ValueSemanticsTest < Minitest::Test
6
+ # ---- StatusCode ----
7
+
8
+ def setup
9
+ @response = Wreq.get("#{HTTPBIN_URL}/status/201")
10
+ end
11
+
12
+ def test_status_code_to_i
13
+ assert_equal 201, @response.status.to_i
14
+ end
15
+
16
+ def test_status_code_as_int_still_works
17
+ assert_equal 201, @response.status.as_int
18
+ end
19
+
20
+ def test_status_code_to_i_matches_as_int
21
+ assert_equal @response.status.as_int, @response.status.to_i
22
+ end
23
+
24
+ def test_status_code_equality
25
+ a = @response.status
26
+ b = @response.status
27
+ assert_equal a, b
28
+ end
29
+
30
+ def test_status_code_eql
31
+ a = @response.status
32
+ b = @response.status
33
+ assert a.eql?(b)
34
+ end
35
+
36
+ def test_status_code_hash_consistent
37
+ a = @response.status
38
+ b = @response.status
39
+ assert_equal a.hash, b.hash
40
+ end
41
+
42
+ def test_status_code_as_hash_key
43
+ status = @response.status
44
+ h = {status => "created"}
45
+ assert_equal "created", h[@response.status]
46
+ end
47
+
48
+ def test_status_code_in_set
49
+ s = Set.new
50
+ s.add(@response.status)
51
+ assert_includes s, @response.status
52
+ end
53
+
54
+ def test_status_code_not_equal_to_integer
55
+ refute_equal @response.status, 201
56
+ refute @response.status.eql?(201)
57
+ end
58
+
59
+ def test_status_code_different_values_not_equal
60
+ ok = Wreq.get("#{HTTPBIN_URL}/status/200").status
61
+ created = @response.status
62
+ refute_equal ok, created
63
+ refute ok.eql?(created)
64
+ end
65
+
66
+ def test_response_code_still_returns_integer
67
+ assert_instance_of Integer, @response.code
68
+ assert_equal 201, @response.code
69
+ end
70
+
71
+ # ---- Version ----
72
+
73
+ def test_version_equality
74
+ assert_equal Wreq::Version::HTTP_11, Wreq::Version::HTTP_11
75
+ assert_equal "HTTP/0.9", Wreq::Version::HTTP_09.to_s
76
+ assert_equal "HTTP/1.0", Wreq::Version::HTTP_10.to_s
77
+ assert_equal "HTTP/1.1", Wreq::Version::HTTP_11.to_s
78
+ assert_equal "HTTP/2.0", Wreq::Version::HTTP_2.to_s
79
+ assert_equal "HTTP/3.0", Wreq::Version::HTTP_3.to_s
80
+ end
81
+
82
+ def test_version_eql
83
+ v = Wreq::Version::HTTP_11
84
+ assert v.eql?(Wreq::Version::HTTP_11)
85
+ end
86
+
87
+ def test_version_hash_consistent
88
+ a = Wreq::Version::HTTP_11
89
+ b = Wreq::Version::HTTP_11
90
+ assert_equal a.hash, b.hash
91
+ end
92
+
93
+ def test_version_different_values_not_equal
94
+ refute_equal Wreq::Version::HTTP_11, Wreq::Version::HTTP_2
95
+ end
96
+
97
+ def test_version_as_hash_key
98
+ v = Wreq::Version::HTTP_11
99
+ h = {v => "http1.1"}
100
+ assert_equal "http1.1", h[Wreq::Version::HTTP_11]
101
+ end
102
+
103
+ def test_version_in_set
104
+ s = Set.new([Wreq::Version::HTTP_11, Wreq::Version::HTTP_2])
105
+ assert_includes s, Wreq::Version::HTTP_11
106
+ assert_includes s, Wreq::Version::HTTP_2
107
+ refute_includes s, Wreq::Version::HTTP_3
108
+ end
109
+
110
+ # ---- Method ----
111
+
112
+ def test_method_to_s
113
+ assert_equal "GET", Wreq::Method::GET.to_s
114
+ assert_equal "POST", Wreq::Method::POST.to_s
115
+ assert_equal "PUT", Wreq::Method::PUT.to_s
116
+ assert_equal "DELETE", Wreq::Method::DELETE.to_s
117
+ assert_equal "HEAD", Wreq::Method::HEAD.to_s
118
+ assert_equal "OPTIONS", Wreq::Method::OPTIONS.to_s
119
+ assert_equal "TRACE", Wreq::Method::TRACE.to_s
120
+ assert_equal "PATCH", Wreq::Method::PATCH.to_s
121
+ end
122
+
123
+ def test_method_to_sym
124
+ assert_equal :get, Wreq::Method::GET.to_sym
125
+ assert_equal :post, Wreq::Method::POST.to_sym
126
+ assert_equal :put, Wreq::Method::PUT.to_sym
127
+ assert_equal :delete, Wreq::Method::DELETE.to_sym
128
+ assert_equal :head, Wreq::Method::HEAD.to_sym
129
+ assert_equal :options, Wreq::Method::OPTIONS.to_sym
130
+ assert_equal :trace, Wreq::Method::TRACE.to_sym
131
+ assert_equal :patch, Wreq::Method::PATCH.to_sym
132
+ end
133
+
134
+ def test_method_equality
135
+ assert_equal Wreq::Method::GET, Wreq::Method::GET
136
+ refute_equal Wreq::Method::GET, Wreq::Method::POST
137
+ end
138
+
139
+ def test_method_eql
140
+ assert Wreq::Method::GET.eql?(Wreq::Method::GET)
141
+ refute Wreq::Method::GET.eql?(Wreq::Method::POST)
142
+ end
143
+
144
+ def test_method_hash_consistent
145
+ assert_equal Wreq::Method::GET.hash, Wreq::Method::GET.hash
146
+ refute_equal Wreq::Method::GET.hash, Wreq::Method::POST.hash
147
+ end
148
+
149
+ def test_method_as_hash_key
150
+ h = {Wreq::Method::GET => "get it"}
151
+ assert_equal "get it", h[Wreq::Method::GET]
152
+ assert_nil h[Wreq::Method::POST]
153
+ end
154
+
155
+ # ---- SameSite ----
156
+
157
+ def test_same_site_to_s
158
+ assert_equal "Strict", Wreq::SameSite::Strict.to_s
159
+ assert_equal "Lax", Wreq::SameSite::Lax.to_s
160
+ assert_equal "None", Wreq::SameSite::None.to_s
161
+ end
162
+
163
+ def test_same_site_to_sym
164
+ assert_equal :strict, Wreq::SameSite::Strict.to_sym
165
+ assert_equal :lax, Wreq::SameSite::Lax.to_sym
166
+ assert_equal :none, Wreq::SameSite::None.to_sym
167
+ end
168
+
169
+ def test_same_site_equality
170
+ assert_equal Wreq::SameSite::Lax, Wreq::SameSite::Lax
171
+ refute_equal Wreq::SameSite::Lax, Wreq::SameSite::Strict
172
+ end
173
+
174
+ def test_same_site_eql_and_hash
175
+ assert Wreq::SameSite::Lax.eql?(Wreq::SameSite::Lax)
176
+ assert_equal Wreq::SameSite::Lax.hash, Wreq::SameSite::Lax.hash
177
+ end
178
+
179
+ # ---- Profile ----
180
+
181
+ def test_profile_equality
182
+ assert_equal Wreq::Profile::Chrome134, Wreq::Profile::Chrome134
183
+ refute_equal Wreq::Profile::Chrome134, Wreq::Profile::Chrome135
184
+ assert_equal "Chrome134", Wreq::Profile::Chrome134.to_s
185
+ assert_equal "SafariIos17_4_1", Wreq::Profile::SafariIos17_4_1.to_s
186
+ assert_equal "OkHttp4_12", Wreq::Profile::OkHttp4_12.to_s
187
+ end
188
+
189
+ def test_profile_eql_and_hash
190
+ assert Wreq::Profile::Chrome134.eql?(Wreq::Profile::Chrome134)
191
+ assert_equal Wreq::Profile::Chrome134.hash, Wreq::Profile::Chrome134.hash
192
+ end
193
+
194
+ def test_profile_as_hash_key
195
+ h = {Wreq::Profile::Chrome134 => "chrome"}
196
+ assert_equal "chrome", h[Wreq::Profile::Chrome134]
197
+ assert_nil h[Wreq::Profile::Chrome135]
198
+ end
199
+
200
+ # ---- Platform ----
201
+
202
+ def test_platform_equality
203
+ assert_equal Wreq::Platform::Windows, Wreq::Platform::Windows
204
+ refute_equal Wreq::Platform::Windows, Wreq::Platform::Linux
205
+ end
206
+
207
+ def test_platform_eql_and_hash
208
+ assert Wreq::Platform::Windows.eql?(Wreq::Platform::Windows)
209
+ assert_equal Wreq::Platform::Windows.hash, Wreq::Platform::Windows.hash
210
+ end
211
+
212
+ def test_platform_to_sym
213
+ assert_equal "Windows", Wreq::Platform::Windows.to_s
214
+ assert_equal "MacOS", Wreq::Platform::MacOS.to_s
215
+ assert_equal "Linux", Wreq::Platform::Linux.to_s
216
+ assert_equal "Android", Wreq::Platform::Android.to_s
217
+ assert_equal "IOS", Wreq::Platform::IOS.to_s
218
+
219
+ assert_equal :windows, Wreq::Platform::Windows.to_sym
220
+ assert_equal :macos, Wreq::Platform::MacOS.to_sym
221
+ assert_equal :linux, Wreq::Platform::Linux.to_sym
222
+ assert_equal :android, Wreq::Platform::Android.to_sym
223
+ assert_equal :ios, Wreq::Platform::IOS.to_sym
224
+ end
225
+
226
+ # ---- Cross-type comparisons ----
227
+
228
+ def test_cross_type_not_equal
229
+ refute_equal Wreq::Method::GET, Wreq::Version::HTTP_11
230
+ refute_equal Wreq::SameSite::Lax, Wreq::Method::GET
231
+ refute_equal Wreq::Platform::Windows, Wreq::Profile::Chrome134
232
+ end
233
+
234
+ def test_cross_type_eql_false
235
+ refute Wreq::Method::GET.eql?(Wreq::Version::HTTP_11)
236
+ refute Wreq::SameSite::Lax.eql?(Wreq::Method::GET)
237
+ end
238
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wreq
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - SearchApi
@@ -27,6 +27,58 @@ files:
27
27
  - README.md
28
28
  - Rakefile
29
29
  - build.rs
30
+ - crates/wreq-util/.github/FUNDING.yml
31
+ - crates/wreq-util/.github/ISSUE_TEMPLATE/bug_report.md
32
+ - crates/wreq-util/.github/ISSUE_TEMPLATE/custom.md
33
+ - crates/wreq-util/.github/ISSUE_TEMPLATE/feature_request.md
34
+ - crates/wreq-util/.github/dependabot.yml
35
+ - crates/wreq-util/.github/workflows/ci.yml
36
+ - crates/wreq-util/.github/workflows/release-plz.yml
37
+ - crates/wreq-util/.gitignore
38
+ - crates/wreq-util/CHANGELOG.md
39
+ - crates/wreq-util/Cargo.toml
40
+ - crates/wreq-util/LICENSE
41
+ - crates/wreq-util/README.md
42
+ - crates/wreq-util/examples/emulate.rs
43
+ - crates/wreq-util/examples/tower_delay.rs
44
+ - crates/wreq-util/release-plz.toml
45
+ - crates/wreq-util/rustfmt.toml
46
+ - crates/wreq-util/src/emulate.rs
47
+ - crates/wreq-util/src/emulate/compress.rs
48
+ - crates/wreq-util/src/emulate/macros.rs
49
+ - crates/wreq-util/src/emulate/profile.rs
50
+ - crates/wreq-util/src/emulate/profile/chrome.rs
51
+ - crates/wreq-util/src/emulate/profile/chrome/header.rs
52
+ - crates/wreq-util/src/emulate/profile/chrome/http2.rs
53
+ - crates/wreq-util/src/emulate/profile/chrome/tls.rs
54
+ - crates/wreq-util/src/emulate/profile/firefox.rs
55
+ - crates/wreq-util/src/emulate/profile/firefox/header.rs
56
+ - crates/wreq-util/src/emulate/profile/firefox/http2.rs
57
+ - crates/wreq-util/src/emulate/profile/firefox/tls.rs
58
+ - crates/wreq-util/src/emulate/profile/okhttp.rs
59
+ - crates/wreq-util/src/emulate/profile/opera.rs
60
+ - crates/wreq-util/src/emulate/profile/opera/header.rs
61
+ - crates/wreq-util/src/emulate/profile/opera/http2.rs
62
+ - crates/wreq-util/src/emulate/profile/opera/tls.rs
63
+ - crates/wreq-util/src/emulate/profile/safari.rs
64
+ - crates/wreq-util/src/emulate/profile/safari/header.rs
65
+ - crates/wreq-util/src/emulate/profile/safari/http2.rs
66
+ - crates/wreq-util/src/emulate/profile/safari/tls.rs
67
+ - crates/wreq-util/src/lib.rs
68
+ - crates/wreq-util/src/rand.rs
69
+ - crates/wreq-util/src/tower.rs
70
+ - crates/wreq-util/src/tower/delay.rs
71
+ - crates/wreq-util/src/tower/delay/future.rs
72
+ - crates/wreq-util/src/tower/delay/layer.rs
73
+ - crates/wreq-util/src/tower/delay/service.rs
74
+ - crates/wreq-util/tests/client.rs
75
+ - crates/wreq-util/tests/emulate_chrome.rs
76
+ - crates/wreq-util/tests/emulate_firefox.rs
77
+ - crates/wreq-util/tests/emulate_okhttp.rs
78
+ - crates/wreq-util/tests/emulate_opera.rs
79
+ - crates/wreq-util/tests/emulate_safari.rs
80
+ - crates/wreq-util/tests/support/mod.rs
81
+ - crates/wreq-util/tests/support/server.rs
30
82
  - docs/windows-gnu-tokio-crash.md
31
83
  - examples/body.rb
32
84
  - examples/client.rb
@@ -68,7 +120,28 @@ files:
68
120
  - src/http.rs
69
121
  - src/lib.rs
70
122
  - src/macros.rs
123
+ - src/options.rs
71
124
  - src/rt.rs
125
+ - src/serde.rs
126
+ - src/serde/de.rs
127
+ - src/serde/de/array_deserializer.rs
128
+ - src/serde/de/array_enumerator.rs
129
+ - src/serde/de/deserializer.rs
130
+ - src/serde/de/enum_deserializer.rs
131
+ - src/serde/de/hash_deserializer.rs
132
+ - src/serde/de/number_deserializer.rs
133
+ - src/serde/de/variant_deserializer.rs
134
+ - src/serde/error.rs
135
+ - src/serde/ser.rs
136
+ - src/serde/ser/enums.rs
137
+ - src/serde/ser/map_serializer.rs
138
+ - src/serde/ser/seq_serializer.rs
139
+ - src/serde/ser/serializer.rs
140
+ - src/serde/ser/struct_serializer.rs
141
+ - src/serde/ser/struct_variant_serializer.rs
142
+ - src/serde/ser/tuple_variant_serializer.rs
143
+ - src/serde/tests.rs
144
+ - test/body_sender_test.rb
72
145
  - test/client_cookie_test.rb
73
146
  - test/client_test.rb
74
147
  - test/cookie_test.rb
@@ -76,13 +149,16 @@ files:
76
149
  - test/error_handling_test.rb
77
150
  - test/header_test.rb
78
151
  - test/inspect_test.rb
152
+ - test/json_precision_test.rb
79
153
  - test/module_methods_test.rb
154
+ - test/option_validation_test.rb
80
155
  - test/orig_header_test.rb
81
156
  - test/request_parameters_test.rb
82
157
  - test/request_test.rb
83
158
  - test/response_test.rb
84
159
  - test/stream_test.rb
85
160
  - test/test_helper.rb
161
+ - test/value_semantics_test.rb
86
162
  - wreq.gemspec
87
163
  homepage: https://github.com/SearchApi/wreq-ruby
88
164
  licenses: