wreq 1.0.0-aarch64-linux → 1.2.0-aarch64-linux
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/README.md +8 -8
- data/examples/cookie.rb +24 -0
- data/examples/{emulation_request.rb → emulate_request.rb} +8 -8
- data/lib/wreq.rb +45 -55
- data/lib/wreq_ruby/3.3/wreq_ruby.so +0 -0
- data/lib/wreq_ruby/3.4/wreq_ruby.so +0 -0
- data/lib/wreq_ruby/4.0/wreq_ruby.so +0 -0
- data/lib/wreq_ruby/client.rb +71 -63
- data/lib/wreq_ruby/cookie.rb +21 -9
- data/lib/wreq_ruby/{emulation.rb → emulate.rb} +74 -29
- data/lib/wreq_ruby/error.rb +1 -3
- data/lib/wreq_ruby/header.rb +8 -0
- data/lib/wreq_ruby/http.rb +14 -0
- data/lib/wreq_ruby/response.rb +22 -21
- 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/stream_test.rb +292 -2
- metadata +6 -4
data/test/stream_test.rb
CHANGED
|
@@ -8,12 +8,16 @@ class StreamTest < Minitest::Test
|
|
|
8
8
|
3.times { |i| sender.push("chunk-#{i}\n") }
|
|
9
9
|
sender.close
|
|
10
10
|
end
|
|
11
|
+
|
|
11
12
|
resp = client.post("http://localhost:8080/post", body: sender, headers: {"Content-Type" => "text/plain"})
|
|
13
|
+
|
|
12
14
|
assert_equal 200, resp.code
|
|
15
|
+
|
|
13
16
|
echoed = resp.json["data"]
|
|
14
17
|
assert_includes echoed, "chunk-0"
|
|
15
18
|
assert_includes echoed, "chunk-1"
|
|
16
19
|
assert_includes echoed, "chunk-2"
|
|
20
|
+
|
|
17
21
|
producer.join
|
|
18
22
|
end
|
|
19
23
|
|
|
@@ -21,12 +25,124 @@ class StreamTest < Minitest::Test
|
|
|
21
25
|
client = Wreq::Client.new
|
|
22
26
|
resp = client.get("http://localhost:8080/stream/5")
|
|
23
27
|
chunks = []
|
|
28
|
+
|
|
24
29
|
resp.chunks do |chunk|
|
|
25
30
|
chunks << chunk
|
|
26
|
-
assert_kind_of String, chunk
|
|
31
|
+
assert_kind_of String, chunk, "Each yielded chunk must be a String"
|
|
27
32
|
assert_match(/\{.*\}/, chunk)
|
|
28
33
|
end
|
|
29
|
-
|
|
34
|
+
|
|
35
|
+
assert_equal 5, chunks.size, "Should yield exactly 5 chunks from /stream/5"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_chunks_yields_binary_encoding
|
|
39
|
+
client = Wreq::Client.new
|
|
40
|
+
resp = client.get("http://localhost:8080/stream/3")
|
|
41
|
+
|
|
42
|
+
resp.chunks do |chunk|
|
|
43
|
+
assert chunk.encoding == Encoding::BINARY || chunk.encoding == Encoding::ASCII_8BIT,
|
|
44
|
+
"Chunk should have binary encoding, got #{chunk.encoding}"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_chunks_with_single_chunk_body
|
|
49
|
+
client = Wreq::Client.new
|
|
50
|
+
resp = client.get("http://localhost:8080/bytes/1024")
|
|
51
|
+
chunk_count = 0
|
|
52
|
+
total_bytes = 0
|
|
53
|
+
|
|
54
|
+
resp.chunks do |chunk|
|
|
55
|
+
chunk_count += 1
|
|
56
|
+
total_bytes += chunk.bytesize
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
assert chunk_count >= 1, "Should yield at least one chunk"
|
|
60
|
+
assert_equal 1024, total_bytes, "Total bytes should match content length"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_chunks_returns_nil
|
|
64
|
+
client = Wreq::Client.new
|
|
65
|
+
resp = client.get("http://localhost:8080/stream/3")
|
|
66
|
+
|
|
67
|
+
result = resp.chunks { |_chunk| :processing }
|
|
68
|
+
|
|
69
|
+
assert_nil result, "chunks should return nil after completion"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def test_chunks_with_empty_body
|
|
73
|
+
client = Wreq::Client.new
|
|
74
|
+
resp = client.get("http://localhost:8080/status/204")
|
|
75
|
+
chunk_count = 0
|
|
76
|
+
|
|
77
|
+
resp.chunks do |_chunk|
|
|
78
|
+
chunk_count += 1
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
assert_equal 0, chunk_count, "No chunks should be yielded for empty 204 response"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def test_chunks_without_block_raises_error
|
|
85
|
+
client = Wreq::Client.new
|
|
86
|
+
resp = client.get("http://localhost:8080/stream/3")
|
|
87
|
+
|
|
88
|
+
assert_raises(LocalJumpError) do
|
|
89
|
+
resp.chunks
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def test_other_threads_run_during_streaming
|
|
94
|
+
client = Wreq::Client.new
|
|
95
|
+
resp = client.get("http://localhost:8080/drip?duration=3&numbytes=3&delay=1")
|
|
96
|
+
|
|
97
|
+
counter = 0
|
|
98
|
+
tick_thread = Thread.new do
|
|
99
|
+
30.times do
|
|
100
|
+
counter += 1
|
|
101
|
+
sleep 0.1
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
chunks_received = 0
|
|
106
|
+
resp.chunks do |_chunk|
|
|
107
|
+
chunks_received += 1
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
tick_thread.join(10)
|
|
111
|
+
|
|
112
|
+
assert counter > 5,
|
|
113
|
+
"Counter only reached #{counter} - other threads may not be running during streaming. " \
|
|
114
|
+
"GVL should be released during I/O waits."
|
|
115
|
+
assert chunks_received >= 1, "Should have received at least one chunk"
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def test_multiple_concurrent_streams
|
|
119
|
+
client = Wreq::Client.new
|
|
120
|
+
results = {}
|
|
121
|
+
done = {}
|
|
122
|
+
|
|
123
|
+
t1 = Thread.new do
|
|
124
|
+
resp = client.get("http://localhost:8080/stream/3")
|
|
125
|
+
chunks = []
|
|
126
|
+
resp.chunks { |chunk| chunks << chunk }
|
|
127
|
+
results[:t1] = chunks.size
|
|
128
|
+
done[:t1] = true
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
t2 = Thread.new do
|
|
132
|
+
resp = client.get("http://localhost:8080/stream/3")
|
|
133
|
+
chunks = []
|
|
134
|
+
resp.chunks { |chunk| chunks << chunk }
|
|
135
|
+
results[:t2] = chunks.size
|
|
136
|
+
done[:t2] = true
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
t1.join(15)
|
|
140
|
+
t2.join(15)
|
|
141
|
+
|
|
142
|
+
assert done[:t1], "Thread 1 should complete"
|
|
143
|
+
assert done[:t2], "Thread 2 should complete"
|
|
144
|
+
assert_equal 3, results[:t1], "Thread 1 should receive 3 chunks"
|
|
145
|
+
assert_equal 3, results[:t2], "Thread 2 should receive 3 chunks"
|
|
30
146
|
end
|
|
31
147
|
|
|
32
148
|
def test_thread_interrupt_connect
|
|
@@ -35,9 +151,11 @@ class StreamTest < Minitest::Test
|
|
|
35
151
|
Wreq.get(url)
|
|
36
152
|
rescue => _
|
|
37
153
|
end
|
|
154
|
+
|
|
38
155
|
sleep 2
|
|
39
156
|
thread.kill
|
|
40
157
|
killed = thread.join(5)
|
|
158
|
+
|
|
41
159
|
assert killed, "Connect phase should be interruptible"
|
|
42
160
|
end
|
|
43
161
|
|
|
@@ -47,9 +165,11 @@ class StreamTest < Minitest::Test
|
|
|
47
165
|
Wreq.get(url, timeout: 60)
|
|
48
166
|
rescue => _
|
|
49
167
|
end
|
|
168
|
+
|
|
50
169
|
sleep 2
|
|
51
170
|
thread.kill
|
|
52
171
|
killed = thread.join(5)
|
|
172
|
+
|
|
53
173
|
assert killed, "Connect+timeout phase should be interruptible"
|
|
54
174
|
end
|
|
55
175
|
|
|
@@ -60,9 +180,11 @@ class StreamTest < Minitest::Test
|
|
|
60
180
|
resp.text
|
|
61
181
|
rescue => _
|
|
62
182
|
end
|
|
183
|
+
|
|
63
184
|
sleep 2
|
|
64
185
|
thread.kill
|
|
65
186
|
killed = thread.join(5)
|
|
187
|
+
|
|
66
188
|
assert killed, "Body reading should be interruptible"
|
|
67
189
|
end
|
|
68
190
|
|
|
@@ -73,9 +195,177 @@ class StreamTest < Minitest::Test
|
|
|
73
195
|
resp.chunks { |chunk| chunk }
|
|
74
196
|
rescue => _
|
|
75
197
|
end
|
|
198
|
+
|
|
76
199
|
sleep 2
|
|
77
200
|
thread.kill
|
|
78
201
|
killed = thread.join(5)
|
|
202
|
+
|
|
79
203
|
assert killed, "Body streaming should be interruptible"
|
|
80
204
|
end
|
|
205
|
+
|
|
206
|
+
def test_thread_interrupt_during_slow_stream_with_block_processing
|
|
207
|
+
url = "http://localhost:8080/drip?duration=5&numbytes=5&delay=1"
|
|
208
|
+
thread = Thread.new do
|
|
209
|
+
resp = Wreq.get(url)
|
|
210
|
+
resp.chunks do |_chunk|
|
|
211
|
+
sleep 0.5
|
|
212
|
+
end
|
|
213
|
+
rescue => _
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
sleep 2
|
|
217
|
+
thread.kill
|
|
218
|
+
killed = thread.join(5)
|
|
219
|
+
|
|
220
|
+
assert killed, "Streaming with slow block processing should be interruptible"
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def test_chunks_propagates_streaming_errors
|
|
224
|
+
client = Wreq::Client.new
|
|
225
|
+
resp = client.get("http://localhost:8080/drip?duration=10&numbytes=10", timeout: 1)
|
|
226
|
+
error_raised = false
|
|
227
|
+
|
|
228
|
+
begin
|
|
229
|
+
resp.chunks do |_chunk|
|
|
230
|
+
end
|
|
231
|
+
rescue => e
|
|
232
|
+
error_raised = true
|
|
233
|
+
assert(
|
|
234
|
+
e.is_a?(Wreq::TimeoutError) || e.is_a?(Wreq::BodyError) || e.is_a?(Wreq::ConnectionResetError),
|
|
235
|
+
"Expected a streaming error (TimeoutError/BodyError/ConnectionResetError), got #{e.class}: #{e.message}"
|
|
236
|
+
)
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
assert error_raised, "A streaming error should have been raised for a timed-out drip response"
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
def test_exception_in_block_propagates
|
|
243
|
+
client = Wreq::Client.new
|
|
244
|
+
resp = client.get("http://localhost:8080/stream/5")
|
|
245
|
+
error_raised = false
|
|
246
|
+
chunks_before_error = 0
|
|
247
|
+
|
|
248
|
+
begin
|
|
249
|
+
resp.chunks do |_chunk|
|
|
250
|
+
chunks_before_error += 1
|
|
251
|
+
raise "intentional error in block" if chunks_before_error == 2
|
|
252
|
+
end
|
|
253
|
+
rescue RuntimeError => e
|
|
254
|
+
error_raised = true
|
|
255
|
+
assert_equal "intentional error in block", e.message
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
assert error_raised, "Exception raised inside the block should propagate out"
|
|
259
|
+
assert_equal 2, chunks_before_error, "Should have processed 2 chunks before the error"
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
def test_chunks_called_twice_raises_error
|
|
263
|
+
client = Wreq::Client.new
|
|
264
|
+
resp = client.get("http://localhost:8080/stream/3")
|
|
265
|
+
resp.chunks { |_chunk| }
|
|
266
|
+
error_raised = false
|
|
267
|
+
|
|
268
|
+
begin
|
|
269
|
+
resp.chunks { |_chunk| }
|
|
270
|
+
rescue => e
|
|
271
|
+
error_raised = true
|
|
272
|
+
assert_instance_of Wreq::MemoryError, e,
|
|
273
|
+
"Second chunks call should raise MemoryError, got #{e.class}: #{e.message}"
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
assert error_raised, "Second chunks call should raise an error"
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
def test_text_after_chunks_raises_error
|
|
280
|
+
client = Wreq::Client.new
|
|
281
|
+
resp = client.get("http://localhost:8080/stream/3")
|
|
282
|
+
resp.chunks { |_chunk| }
|
|
283
|
+
error_raised = false
|
|
284
|
+
|
|
285
|
+
begin
|
|
286
|
+
resp.text
|
|
287
|
+
rescue => e
|
|
288
|
+
error_raised = true
|
|
289
|
+
assert_instance_of Wreq::MemoryError, e,
|
|
290
|
+
"Calling text after chunks should raise MemoryError, got #{e.class}: #{e.message}"
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
assert error_raised, "Calling text after chunks should raise an error"
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
def test_chunks_content_matches_full_body
|
|
297
|
+
client = Wreq::Client.new
|
|
298
|
+
resp_full = client.get("http://localhost:8080/bytes/4096")
|
|
299
|
+
full_bytes = resp_full.bytes
|
|
300
|
+
|
|
301
|
+
resp_stream = client.get("http://localhost:8080/bytes/4096")
|
|
302
|
+
streamed_bytes = "".b
|
|
303
|
+
resp_stream.chunks do |chunk|
|
|
304
|
+
streamed_bytes << chunk
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
assert_equal full_bytes.bytesize, streamed_bytes.bytesize,
|
|
308
|
+
"Streamed body size should match full body size"
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
def test_chunks_json_stream_content
|
|
312
|
+
client = Wreq::Client.new
|
|
313
|
+
resp = client.get("http://localhost:8080/stream/5")
|
|
314
|
+
chunks = []
|
|
315
|
+
|
|
316
|
+
resp.chunks do |chunk|
|
|
317
|
+
chunks << chunk
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
chunks.each_with_index do |chunk, i|
|
|
321
|
+
assert_match(/\{.*\}/, chunk,
|
|
322
|
+
"Chunk #{i} should contain a JSON object, got: #{chunk[0..80]}")
|
|
323
|
+
end
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
def test_block_not_garbage_collected_during_streaming
|
|
327
|
+
client = Wreq::Client.new
|
|
328
|
+
resp = client.get("http://localhost:8080/drip?duration=3&numbytes=3&delay=1")
|
|
329
|
+
chunks_received = 0
|
|
330
|
+
|
|
331
|
+
resp.chunks do |_chunk|
|
|
332
|
+
chunks_received += 1
|
|
333
|
+
GC.start
|
|
334
|
+
GC.start
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
assert_equal 3, chunks_received,
|
|
338
|
+
"All 3 chunks should be received even with forced GC between yields"
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
def test_close_after_streaming
|
|
342
|
+
client = Wreq::Client.new
|
|
343
|
+
resp = client.get("http://localhost:8080/stream/3")
|
|
344
|
+
|
|
345
|
+
resp.chunks { |_chunk| }
|
|
346
|
+
resp.close
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
def test_chunks_via_module_method
|
|
350
|
+
resp = Wreq.get("http://localhost:8080/stream/3")
|
|
351
|
+
chunks = []
|
|
352
|
+
|
|
353
|
+
resp.chunks do |chunk|
|
|
354
|
+
chunks << chunk
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
assert_equal 3, chunks.size, "Module-level Wreq.get + chunks should work"
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
def test_chunks_via_client_instance
|
|
361
|
+
client = Wreq::Client.new
|
|
362
|
+
resp = client.get("http://localhost:8080/stream/3")
|
|
363
|
+
chunks = []
|
|
364
|
+
|
|
365
|
+
resp.chunks do |chunk|
|
|
366
|
+
chunks << chunk
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
assert_equal 3, chunks.size, "Client instance get + chunks should work"
|
|
370
|
+
end
|
|
81
371
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: wreq
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
platform: aarch64-linux
|
|
6
6
|
authors:
|
|
7
7
|
- SearchApi
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-06-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: An easy and powerful Ruby HTTP client with advanced browser fingerprinting
|
|
14
14
|
that accurately emulates Chrome, Edge, Firefox, Safari, Opera, and OkHttp with precise
|
|
@@ -26,7 +26,8 @@ files:
|
|
|
26
26
|
- Rakefile
|
|
27
27
|
- examples/body.rb
|
|
28
28
|
- examples/client.rb
|
|
29
|
-
- examples/
|
|
29
|
+
- examples/cookie.rb
|
|
30
|
+
- examples/emulate_request.rb
|
|
30
31
|
- examples/headers.rb
|
|
31
32
|
- examples/proxy.rb
|
|
32
33
|
- examples/send_stream.rb
|
|
@@ -39,7 +40,7 @@ files:
|
|
|
39
40
|
- lib/wreq_ruby/body.rb
|
|
40
41
|
- lib/wreq_ruby/client.rb
|
|
41
42
|
- lib/wreq_ruby/cookie.rb
|
|
42
|
-
- lib/wreq_ruby/
|
|
43
|
+
- lib/wreq_ruby/emulate.rb
|
|
43
44
|
- lib/wreq_ruby/error.rb
|
|
44
45
|
- lib/wreq_ruby/header.rb
|
|
45
46
|
- lib/wreq_ruby/http.rb
|
|
@@ -51,6 +52,7 @@ files:
|
|
|
51
52
|
- test/emulation_test.rb
|
|
52
53
|
- test/error_handling_test.rb
|
|
53
54
|
- test/header_test.rb
|
|
55
|
+
- test/inspect_test.rb
|
|
54
56
|
- test/module_methods_test.rb
|
|
55
57
|
- test/request_parameters_test.rb
|
|
56
58
|
- test/request_test.rb
|