wreq 1.2.2 → 1.2.3
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 +41 -63
- data/Cargo.toml +1 -1
- data/Gemfile +1 -0
- data/README.md +7 -4
- data/build.rs +7 -0
- data/docs/windows-gnu-tokio-crash.md +70 -0
- data/lib/wreq_ruby/emulate.rb +1 -0
- data/script/build_windows_gnu.ps1 +257 -0
- data/src/arch.rs +33 -0
- data/src/client/body/stream.rs +12 -9
- data/src/client/req.rs +122 -110
- data/src/client/resp.rs +9 -17
- data/src/client.rs +13 -0
- data/src/emulate.rs +1 -0
- data/src/lib.rs +1 -0
- data/src/rt.rs +26 -9
- data/test/client_cookie_test.rb +6 -6
- data/test/client_test.rb +16 -16
- data/test/cookie_test.rb +8 -6
- data/test/error_handling_test.rb +4 -4
- data/test/header_test.rb +1 -1
- data/test/inspect_test.rb +4 -4
- data/test/module_methods_test.rb +11 -11
- data/test/request_parameters_test.rb +30 -30
- data/test/request_test.rb +22 -22
- data/test/response_test.rb +6 -6
- data/test/stream_test.rb +61 -35
- data/test/test_helper.rb +46 -3
- metadata +4 -1
data/test/request_test.rb
CHANGED
|
@@ -17,25 +17,25 @@ class WreqHttpbinTest < Minitest::Test
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def test_module_get_method
|
|
20
|
-
response = Wreq.get("
|
|
20
|
+
response = Wreq.get("#{HTTPBIN_URL}/get")
|
|
21
21
|
assert_equal 200, response.code
|
|
22
22
|
assert_respond_to response, :text
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def test_module_post_with_json
|
|
26
26
|
data = {name: "wreq-ruby", version: "0.1.0"}
|
|
27
|
-
response = Wreq.post("
|
|
27
|
+
response = Wreq.post("#{HTTPBIN_URL}/post", json: data)
|
|
28
28
|
assert_equal 200, response.code
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def test_client_instance_basic
|
|
32
|
-
response = @client.get("
|
|
32
|
+
response = @client.get("#{HTTPBIN_URL}/get")
|
|
33
33
|
assert_equal 200, response.code
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def test_client_with_custom_headers
|
|
37
37
|
headers = {"User-Agent" => "wreq-ruby/test", "Accept" => "application/json"}
|
|
38
|
-
response = @client.get("
|
|
38
|
+
response = @client.get("#{HTTPBIN_URL}/headers", headers: headers)
|
|
39
39
|
assert_equal 200, response.code
|
|
40
40
|
end
|
|
41
41
|
|
|
@@ -51,14 +51,14 @@ class WreqHttpbinTest < Minitest::Test
|
|
|
51
51
|
]
|
|
52
52
|
|
|
53
53
|
methods.each do |method|
|
|
54
|
-
response = @client.request(method, "
|
|
54
|
+
response = @client.request(method, "#{HTTPBIN_URL}/anything")
|
|
55
55
|
assert [200, 405].include?(response.code), "client.#{method} failed with status #{response.code}"
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
def test_request_with_query_params
|
|
60
60
|
params = {"param1" => "value1", "param2" => "value2", "param3" => 123, "param4" => true}
|
|
61
|
-
response = Wreq.get("
|
|
61
|
+
response = Wreq.get("#{HTTPBIN_URL}/get", query: params)
|
|
62
62
|
assert_equal 200, response.code
|
|
63
63
|
assert_includes response.text, "param1=value1"
|
|
64
64
|
assert_includes response.text, "param2=value2"
|
|
@@ -68,7 +68,7 @@ class WreqHttpbinTest < Minitest::Test
|
|
|
68
68
|
|
|
69
69
|
def test_post_with_form_data
|
|
70
70
|
data = {"field1" => "value1", "field2" => "value2", "field3" => 456, "field4" => false}
|
|
71
|
-
response = Wreq.post("
|
|
71
|
+
response = Wreq.post("#{HTTPBIN_URL}/post", form: data)
|
|
72
72
|
assert_equal 200, response.code
|
|
73
73
|
assert_includes response.text, "field1"
|
|
74
74
|
assert_includes response.text, "value1"
|
|
@@ -83,33 +83,33 @@ class WreqHttpbinTest < Minitest::Test
|
|
|
83
83
|
def test_post_with_raw_body
|
|
84
84
|
body = "This is raw body content"
|
|
85
85
|
headers = {"Content-Type" => "text/plain"}
|
|
86
|
-
response = Wreq.post("
|
|
86
|
+
response = Wreq.post("#{HTTPBIN_URL}/post", body: body, headers: headers)
|
|
87
87
|
assert_equal 200, response.code
|
|
88
88
|
assert_includes response.text, body
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
def test_basic_authentication
|
|
92
|
-
response = Wreq.get("
|
|
92
|
+
response = Wreq.get("#{HTTPBIN_URL}/basic-auth/user/pass", basic_auth: ["user", "pass"])
|
|
93
93
|
assert_equal 200, response.code
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
def test_bearer_authentication
|
|
97
|
-
response = Wreq.get("
|
|
97
|
+
response = Wreq.get("#{HTTPBIN_URL}/bearer", bearer_auth: "test-token")
|
|
98
98
|
assert_equal 200, response.code
|
|
99
99
|
end
|
|
100
100
|
|
|
101
101
|
def test_redirect_following
|
|
102
|
-
response = Wreq.get("
|
|
102
|
+
response = Wreq.get("#{HTTPBIN_URL}/redirect/2", allow_redirects: true)
|
|
103
103
|
assert_equal 200, response.code
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
def test_redirect_blocking
|
|
107
|
-
response = Wreq.get("
|
|
107
|
+
response = Wreq.get("#{HTTPBIN_URL}/redirect/1", allow_redirects: false)
|
|
108
108
|
assert_equal 302, response.code
|
|
109
109
|
end
|
|
110
110
|
|
|
111
111
|
def test_response_status_methods
|
|
112
|
-
response = Wreq.get("
|
|
112
|
+
response = Wreq.get("#{HTTPBIN_URL}/status/200")
|
|
113
113
|
assert_equal 200, response.code
|
|
114
114
|
|
|
115
115
|
if response.status.respond_to?(:success?)
|
|
@@ -118,7 +118,7 @@ class WreqHttpbinTest < Minitest::Test
|
|
|
118
118
|
end
|
|
119
119
|
|
|
120
120
|
def test_404_response
|
|
121
|
-
response = Wreq.get("
|
|
121
|
+
response = Wreq.get("#{HTTPBIN_URL}/status/404")
|
|
122
122
|
assert_equal 404, response.code
|
|
123
123
|
|
|
124
124
|
if response.status.respond_to?(:client_error?)
|
|
@@ -127,7 +127,7 @@ class WreqHttpbinTest < Minitest::Test
|
|
|
127
127
|
end
|
|
128
128
|
|
|
129
129
|
def test_json_response_parsing
|
|
130
|
-
response = Wreq.get("
|
|
130
|
+
response = Wreq.get("#{HTTPBIN_URL}/json")
|
|
131
131
|
assert_equal 200, response.code
|
|
132
132
|
|
|
133
133
|
if response.respond_to?(:json)
|
|
@@ -137,12 +137,12 @@ class WreqHttpbinTest < Minitest::Test
|
|
|
137
137
|
end
|
|
138
138
|
|
|
139
139
|
def test_gzip_compression
|
|
140
|
-
response = Wreq.get("
|
|
140
|
+
response = Wreq.get("#{HTTPBIN_URL}/gzip", gzip: true)
|
|
141
141
|
assert_equal 200, response.code
|
|
142
142
|
end
|
|
143
143
|
|
|
144
144
|
def test_headers_iteration
|
|
145
|
-
response = Wreq.get("
|
|
145
|
+
response = Wreq.get("#{HTTPBIN_URL}/get")
|
|
146
146
|
|
|
147
147
|
if response.respond_to?(:each_header)
|
|
148
148
|
count = 0
|
|
@@ -157,7 +157,7 @@ class WreqHttpbinTest < Minitest::Test
|
|
|
157
157
|
end
|
|
158
158
|
|
|
159
159
|
def test_response_properties
|
|
160
|
-
response = Wreq.get("
|
|
160
|
+
response = Wreq.get("#{HTTPBIN_URL}/get")
|
|
161
161
|
|
|
162
162
|
assert_respond_to response, :code
|
|
163
163
|
assert_respond_to response, :status
|
|
@@ -171,12 +171,12 @@ class WreqHttpbinTest < Minitest::Test
|
|
|
171
171
|
def test_timeout_functionality
|
|
172
172
|
# Test that short timeouts properly raise exceptions
|
|
173
173
|
assert_raises(Wreq::TimeoutError) do
|
|
174
|
-
Wreq.get("
|
|
174
|
+
Wreq.get("#{HTTPBIN_URL}/delay/10", timeout: 1)
|
|
175
175
|
end
|
|
176
176
|
|
|
177
177
|
# Test that reasonable timeouts work normally
|
|
178
178
|
start_time = Time.now
|
|
179
|
-
response = Wreq.get("
|
|
179
|
+
response = Wreq.get("#{HTTPBIN_URL}/delay/1", timeout: 5)
|
|
180
180
|
elapsed = Time.now - start_time
|
|
181
181
|
|
|
182
182
|
assert_equal 200, response.code
|
|
@@ -187,7 +187,7 @@ class WreqHttpbinTest < Minitest::Test
|
|
|
187
187
|
start_time = Time.now
|
|
188
188
|
|
|
189
189
|
3.times do |i|
|
|
190
|
-
response = Wreq.get("
|
|
190
|
+
response = Wreq.get("#{HTTPBIN_URL}/get?request=#{i}")
|
|
191
191
|
assert_equal 200, response.code
|
|
192
192
|
end
|
|
193
193
|
|
|
@@ -212,7 +212,7 @@ class WreqHttpbinTest < Minitest::Test
|
|
|
212
212
|
assert_instance_of Wreq::Client, client
|
|
213
213
|
|
|
214
214
|
# Test that it can make requests
|
|
215
|
-
response = client.get("
|
|
215
|
+
response = client.get("#{HTTPBIN_URL}/get")
|
|
216
216
|
assert_equal 200, response.code
|
|
217
217
|
end
|
|
218
218
|
|
data/test/response_test.rb
CHANGED
|
@@ -2,7 +2,7 @@ require "test_helper"
|
|
|
2
2
|
|
|
3
3
|
class ResponseTest < Minitest::Test
|
|
4
4
|
def setup
|
|
5
|
-
@response = Wreq.get("
|
|
5
|
+
@response = Wreq.get("#{HTTPBIN_URL}/json")
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
def test_response_code
|
|
@@ -39,7 +39,7 @@ class ResponseTest < Minitest::Test
|
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def test_response_with_non_json_content
|
|
42
|
-
response = Wreq.get("
|
|
42
|
+
response = Wreq.get("#{HTTPBIN_URL}/html")
|
|
43
43
|
assert_equal 200, response.code
|
|
44
44
|
assert_instance_of String, response.text
|
|
45
45
|
assert response.text.include?("<html>")
|
|
@@ -51,19 +51,19 @@ class ResponseTest < Minitest::Test
|
|
|
51
51
|
def test_response_status_codes
|
|
52
52
|
# Test different status codes
|
|
53
53
|
[200, 404, 500].each do |status|
|
|
54
|
-
response = Wreq.get("
|
|
54
|
+
response = Wreq.get("#{HTTPBIN_URL}/status/#{status}")
|
|
55
55
|
assert_equal status, response.code
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
def test_response_with_query_parameters
|
|
60
|
-
response = Wreq.get("
|
|
60
|
+
response = Wreq.get("#{HTTPBIN_URL}/get",
|
|
61
61
|
query: {"param1" => "value1", "param2" => "value2"})
|
|
62
62
|
assert_equal 200, response.code
|
|
63
63
|
|
|
64
64
|
json_data = response.json
|
|
65
65
|
args = json_data["args"]
|
|
66
|
-
assert_equal "value1", args
|
|
67
|
-
assert_equal "value2", args
|
|
66
|
+
assert_equal "value1", httpbin_fetch(args, "param1")
|
|
67
|
+
assert_equal "value2", httpbin_fetch(args, "param2")
|
|
68
68
|
end
|
|
69
69
|
end
|
data/test/stream_test.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require "test_helper"
|
|
2
|
+
require "socket"
|
|
2
3
|
|
|
3
4
|
class StreamTest < Minitest::Test
|
|
4
5
|
def test_simple_push_stream
|
|
@@ -9,7 +10,7 @@ class StreamTest < Minitest::Test
|
|
|
9
10
|
sender.close
|
|
10
11
|
end
|
|
11
12
|
|
|
12
|
-
resp = client.post("
|
|
13
|
+
resp = client.post("#{HTTPBIN_URL}/post", body: sender, headers: {"Content-Type" => "text/plain"})
|
|
13
14
|
|
|
14
15
|
assert_equal 200, resp.code
|
|
15
16
|
|
|
@@ -23,7 +24,7 @@ class StreamTest < Minitest::Test
|
|
|
23
24
|
|
|
24
25
|
def test_response_body_chunks_stream
|
|
25
26
|
client = Wreq::Client.new
|
|
26
|
-
resp = client.get("
|
|
27
|
+
resp = client.get("#{HTTPBIN_URL}/stream/5")
|
|
27
28
|
chunks = []
|
|
28
29
|
|
|
29
30
|
resp.chunks do |chunk|
|
|
@@ -37,7 +38,7 @@ class StreamTest < Minitest::Test
|
|
|
37
38
|
|
|
38
39
|
def test_chunks_yields_binary_encoding
|
|
39
40
|
client = Wreq::Client.new
|
|
40
|
-
resp = client.get("
|
|
41
|
+
resp = client.get("#{HTTPBIN_URL}/stream/3")
|
|
41
42
|
|
|
42
43
|
resp.chunks do |chunk|
|
|
43
44
|
assert chunk.encoding == Encoding::BINARY || chunk.encoding == Encoding::ASCII_8BIT,
|
|
@@ -47,7 +48,7 @@ class StreamTest < Minitest::Test
|
|
|
47
48
|
|
|
48
49
|
def test_chunks_with_single_chunk_body
|
|
49
50
|
client = Wreq::Client.new
|
|
50
|
-
resp = client.get("
|
|
51
|
+
resp = client.get("#{HTTPBIN_URL}/bytes/1024")
|
|
51
52
|
chunk_count = 0
|
|
52
53
|
total_bytes = 0
|
|
53
54
|
|
|
@@ -62,7 +63,7 @@ class StreamTest < Minitest::Test
|
|
|
62
63
|
|
|
63
64
|
def test_chunks_returns_nil
|
|
64
65
|
client = Wreq::Client.new
|
|
65
|
-
resp = client.get("
|
|
66
|
+
resp = client.get("#{HTTPBIN_URL}/stream/3")
|
|
66
67
|
|
|
67
68
|
result = resp.chunks { |_chunk| :processing }
|
|
68
69
|
|
|
@@ -71,7 +72,7 @@ class StreamTest < Minitest::Test
|
|
|
71
72
|
|
|
72
73
|
def test_chunks_with_empty_body
|
|
73
74
|
client = Wreq::Client.new
|
|
74
|
-
resp = client.get("
|
|
75
|
+
resp = client.get("#{HTTPBIN_URL}/status/204")
|
|
75
76
|
chunk_count = 0
|
|
76
77
|
|
|
77
78
|
resp.chunks do |_chunk|
|
|
@@ -83,7 +84,7 @@ class StreamTest < Minitest::Test
|
|
|
83
84
|
|
|
84
85
|
def test_chunks_without_block_raises_error
|
|
85
86
|
client = Wreq::Client.new
|
|
86
|
-
resp = client.get("
|
|
87
|
+
resp = client.get("#{HTTPBIN_URL}/stream/3")
|
|
87
88
|
|
|
88
89
|
assert_raises(LocalJumpError) do
|
|
89
90
|
resp.chunks
|
|
@@ -92,7 +93,7 @@ class StreamTest < Minitest::Test
|
|
|
92
93
|
|
|
93
94
|
def test_other_threads_run_during_streaming
|
|
94
95
|
client = Wreq::Client.new
|
|
95
|
-
resp = client.get("
|
|
96
|
+
resp = client.get("#{HTTPBIN_URL}/drip?duration=3&numbytes=3&delay=1")
|
|
96
97
|
|
|
97
98
|
counter = 0
|
|
98
99
|
tick_thread = Thread.new do
|
|
@@ -121,7 +122,7 @@ class StreamTest < Minitest::Test
|
|
|
121
122
|
done = {}
|
|
122
123
|
|
|
123
124
|
t1 = Thread.new do
|
|
124
|
-
resp = client.get("
|
|
125
|
+
resp = client.get("#{HTTPBIN_URL}/stream/3")
|
|
125
126
|
chunks = []
|
|
126
127
|
resp.chunks { |chunk| chunks << chunk }
|
|
127
128
|
results[:t1] = chunks.size
|
|
@@ -129,7 +130,7 @@ class StreamTest < Minitest::Test
|
|
|
129
130
|
end
|
|
130
131
|
|
|
131
132
|
t2 = Thread.new do
|
|
132
|
-
resp = client.get("
|
|
133
|
+
resp = client.get("#{HTTPBIN_URL}/stream/3")
|
|
133
134
|
chunks = []
|
|
134
135
|
resp.chunks { |chunk| chunks << chunk }
|
|
135
136
|
results[:t2] = chunks.size
|
|
@@ -174,7 +175,7 @@ class StreamTest < Minitest::Test
|
|
|
174
175
|
end
|
|
175
176
|
|
|
176
177
|
def test_thread_interrupt_body_reading
|
|
177
|
-
url = "
|
|
178
|
+
url = "#{HTTPBIN_URL}/drip?duration=5&numbytes=5"
|
|
178
179
|
thread = Thread.new do
|
|
179
180
|
resp = Wreq.get(url)
|
|
180
181
|
resp.text
|
|
@@ -189,7 +190,7 @@ class StreamTest < Minitest::Test
|
|
|
189
190
|
end
|
|
190
191
|
|
|
191
192
|
def test_thread_interrupt_body_streaming
|
|
192
|
-
url = "
|
|
193
|
+
url = "#{HTTPBIN_URL}/drip?duration=5&numbytes=5"
|
|
193
194
|
thread = Thread.new do
|
|
194
195
|
resp = Wreq.get(url)
|
|
195
196
|
resp.chunks { |chunk| chunk }
|
|
@@ -204,7 +205,7 @@ class StreamTest < Minitest::Test
|
|
|
204
205
|
end
|
|
205
206
|
|
|
206
207
|
def test_thread_interrupt_during_slow_stream_with_block_processing
|
|
207
|
-
url = "
|
|
208
|
+
url = "#{HTTPBIN_URL}/drip?duration=5&numbytes=5&delay=1"
|
|
208
209
|
thread = Thread.new do
|
|
209
210
|
resp = Wreq.get(url)
|
|
210
211
|
resp.chunks do |_chunk|
|
|
@@ -222,26 +223,21 @@ class StreamTest < Minitest::Test
|
|
|
222
223
|
|
|
223
224
|
def test_chunks_propagates_streaming_errors
|
|
224
225
|
client = Wreq::Client.new
|
|
225
|
-
resp = client.get("http://localhost:8080/drip?duration=10&numbytes=10", timeout: 1)
|
|
226
|
-
error_raised = false
|
|
227
226
|
|
|
228
|
-
|
|
229
|
-
resp
|
|
227
|
+
with_truncated_chunked_response do |url|
|
|
228
|
+
resp = client.get(url)
|
|
229
|
+
error = assert_raises(Wreq::BodyError, Wreq::ConnectionResetError, Wreq::DecodingError) do
|
|
230
|
+
resp.chunks do |_chunk|
|
|
231
|
+
end
|
|
230
232
|
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
233
|
|
|
239
|
-
|
|
234
|
+
assert_match(/body|connection|decode|incomplete|closed|unexpected/i, error.message)
|
|
235
|
+
end
|
|
240
236
|
end
|
|
241
237
|
|
|
242
238
|
def test_exception_in_block_propagates
|
|
243
239
|
client = Wreq::Client.new
|
|
244
|
-
resp = client.get("
|
|
240
|
+
resp = client.get("#{HTTPBIN_URL}/stream/5")
|
|
245
241
|
error_raised = false
|
|
246
242
|
chunks_before_error = 0
|
|
247
243
|
|
|
@@ -261,7 +257,7 @@ class StreamTest < Minitest::Test
|
|
|
261
257
|
|
|
262
258
|
def test_chunks_called_twice_raises_error
|
|
263
259
|
client = Wreq::Client.new
|
|
264
|
-
resp = client.get("
|
|
260
|
+
resp = client.get("#{HTTPBIN_URL}/stream/3")
|
|
265
261
|
resp.chunks { |_chunk| }
|
|
266
262
|
error_raised = false
|
|
267
263
|
|
|
@@ -278,7 +274,7 @@ class StreamTest < Minitest::Test
|
|
|
278
274
|
|
|
279
275
|
def test_text_after_chunks_raises_error
|
|
280
276
|
client = Wreq::Client.new
|
|
281
|
-
resp = client.get("
|
|
277
|
+
resp = client.get("#{HTTPBIN_URL}/stream/3")
|
|
282
278
|
resp.chunks { |_chunk| }
|
|
283
279
|
error_raised = false
|
|
284
280
|
|
|
@@ -295,10 +291,10 @@ class StreamTest < Minitest::Test
|
|
|
295
291
|
|
|
296
292
|
def test_chunks_content_matches_full_body
|
|
297
293
|
client = Wreq::Client.new
|
|
298
|
-
resp_full = client.get("
|
|
294
|
+
resp_full = client.get("#{HTTPBIN_URL}/bytes/4096")
|
|
299
295
|
full_bytes = resp_full.bytes
|
|
300
296
|
|
|
301
|
-
resp_stream = client.get("
|
|
297
|
+
resp_stream = client.get("#{HTTPBIN_URL}/bytes/4096")
|
|
302
298
|
streamed_bytes = "".b
|
|
303
299
|
resp_stream.chunks do |chunk|
|
|
304
300
|
streamed_bytes << chunk
|
|
@@ -310,7 +306,7 @@ class StreamTest < Minitest::Test
|
|
|
310
306
|
|
|
311
307
|
def test_chunks_json_stream_content
|
|
312
308
|
client = Wreq::Client.new
|
|
313
|
-
resp = client.get("
|
|
309
|
+
resp = client.get("#{HTTPBIN_URL}/stream/5")
|
|
314
310
|
chunks = []
|
|
315
311
|
|
|
316
312
|
resp.chunks do |chunk|
|
|
@@ -325,7 +321,7 @@ class StreamTest < Minitest::Test
|
|
|
325
321
|
|
|
326
322
|
def test_block_not_garbage_collected_during_streaming
|
|
327
323
|
client = Wreq::Client.new
|
|
328
|
-
resp = client.get("
|
|
324
|
+
resp = client.get("#{HTTPBIN_URL}/stream/3")
|
|
329
325
|
chunks_received = 0
|
|
330
326
|
|
|
331
327
|
resp.chunks do |_chunk|
|
|
@@ -340,14 +336,14 @@ class StreamTest < Minitest::Test
|
|
|
340
336
|
|
|
341
337
|
def test_close_after_streaming
|
|
342
338
|
client = Wreq::Client.new
|
|
343
|
-
resp = client.get("
|
|
339
|
+
resp = client.get("#{HTTPBIN_URL}/stream/3")
|
|
344
340
|
|
|
345
341
|
resp.chunks { |_chunk| }
|
|
346
342
|
resp.close
|
|
347
343
|
end
|
|
348
344
|
|
|
349
345
|
def test_chunks_via_module_method
|
|
350
|
-
resp = Wreq.get("
|
|
346
|
+
resp = Wreq.get("#{HTTPBIN_URL}/stream/3")
|
|
351
347
|
chunks = []
|
|
352
348
|
|
|
353
349
|
resp.chunks do |chunk|
|
|
@@ -359,7 +355,7 @@ class StreamTest < Minitest::Test
|
|
|
359
355
|
|
|
360
356
|
def test_chunks_via_client_instance
|
|
361
357
|
client = Wreq::Client.new
|
|
362
|
-
resp = client.get("
|
|
358
|
+
resp = client.get("#{HTTPBIN_URL}/stream/3")
|
|
363
359
|
chunks = []
|
|
364
360
|
|
|
365
361
|
resp.chunks do |chunk|
|
|
@@ -368,4 +364,34 @@ class StreamTest < Minitest::Test
|
|
|
368
364
|
|
|
369
365
|
assert_equal 3, chunks.size, "Client instance get + chunks should work"
|
|
370
366
|
end
|
|
367
|
+
|
|
368
|
+
private
|
|
369
|
+
|
|
370
|
+
def with_truncated_chunked_response
|
|
371
|
+
server = TCPServer.new("127.0.0.1", 0)
|
|
372
|
+
port = server.addr[1]
|
|
373
|
+
thread = Thread.new do
|
|
374
|
+
socket = server.accept
|
|
375
|
+
begin
|
|
376
|
+
socket.readpartial(4096) if IO.select([socket], nil, nil, 5)
|
|
377
|
+
socket.write "HTTP/1.1 200 OK\r\n"
|
|
378
|
+
socket.write "Content-Type: text/plain\r\n"
|
|
379
|
+
socket.write "Transfer-Encoding: chunked\r\n"
|
|
380
|
+
socket.write "\r\n"
|
|
381
|
+
socket.write "5\r\nhello\r\n"
|
|
382
|
+
socket.write "A\r\nshort"
|
|
383
|
+
ensure
|
|
384
|
+
socket.close unless socket.closed?
|
|
385
|
+
end
|
|
386
|
+
rescue IOError, SystemCallError
|
|
387
|
+
ensure
|
|
388
|
+
server.close unless server.closed?
|
|
389
|
+
end
|
|
390
|
+
thread.report_on_exception = false
|
|
391
|
+
|
|
392
|
+
yield "http://127.0.0.1:#{port}/"
|
|
393
|
+
ensure
|
|
394
|
+
server&.close unless server&.closed?
|
|
395
|
+
thread&.join(5)
|
|
396
|
+
end
|
|
371
397
|
end
|
data/test/test_helper.rb
CHANGED
|
@@ -1,9 +1,52 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
4
|
-
# Run httpbin server: `docker run -d -p 8080:80 --name httpbin kennethreitz/httpbin`
|
|
5
|
-
|
|
6
3
|
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
|
|
7
4
|
require "wreq"
|
|
8
5
|
|
|
6
|
+
HTTPBIN_URL = ENV.fetch("HTTPBIN_URL", "https://httpbin.io").delete_suffix("/")
|
|
7
|
+
MINITEST_RETRY_COUNT = Integer(ENV.fetch("MINITEST_RETRY_COUNT", "3"))
|
|
8
|
+
MINITEST_RETRY_DISPLAY_FAILURE_MESSAGES =
|
|
9
|
+
ENV.fetch("MINITEST_RETRY_DISPLAY_FAILURE_MESSAGES", "true") != "false"
|
|
10
|
+
MINITEST_RETRY_SLEEP_INTERVAL = Float(ENV.fetch("MINITEST_RETRY_SLEEP_INTERVAL", "1"))
|
|
11
|
+
|
|
9
12
|
require "minitest/autorun"
|
|
13
|
+
require "minitest/retry"
|
|
14
|
+
|
|
15
|
+
# httpbin.io is a shared external service, so the integration tests can see
|
|
16
|
+
# occasional network failures even when the client behavior is correct.
|
|
17
|
+
Minitest::Retry.use!(
|
|
18
|
+
retry_count: MINITEST_RETRY_COUNT,
|
|
19
|
+
verbose: false,
|
|
20
|
+
io: $stderr
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
Minitest::Retry.on_retry do |klass, test_name, attempt, result|
|
|
24
|
+
$stderr.puts "[MinitestRetry] retry #{klass}##{test_name} (#{attempt}/#{MINITEST_RETRY_COUNT})"
|
|
25
|
+
|
|
26
|
+
if MINITEST_RETRY_DISPLAY_FAILURE_MESSAGES
|
|
27
|
+
result.failures.each do |failure|
|
|
28
|
+
message = failure.message.to_s.strip
|
|
29
|
+
$stderr.puts message unless message.empty?
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
sleep MINITEST_RETRY_SLEEP_INTERVAL if MINITEST_RETRY_SLEEP_INTERVAL.positive?
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
module HttpbinHelpers
|
|
37
|
+
def httpbin_value(value)
|
|
38
|
+
(value.is_a?(Array) && value.length == 1) ? value.first : value
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def httpbin_fetch(hash, key)
|
|
42
|
+
httpbin_value(hash.fetch(key))
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def httpbin_cookies(json)
|
|
46
|
+
json.fetch("cookies", json)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
class Minitest::Test
|
|
51
|
+
include HttpbinHelpers
|
|
52
|
+
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
|
+
version: 1.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- SearchApi
|
|
@@ -27,6 +27,7 @@ files:
|
|
|
27
27
|
- README.md
|
|
28
28
|
- Rakefile
|
|
29
29
|
- build.rs
|
|
30
|
+
- docs/windows-gnu-tokio-crash.md
|
|
30
31
|
- examples/body.rb
|
|
31
32
|
- examples/client.rb
|
|
32
33
|
- examples/cookie.rb
|
|
@@ -47,6 +48,8 @@ files:
|
|
|
47
48
|
- lib/wreq_ruby/http.rb
|
|
48
49
|
- lib/wreq_ruby/response.rb
|
|
49
50
|
- script/build_platform_gem.rb
|
|
51
|
+
- script/build_windows_gnu.ps1
|
|
52
|
+
- src/arch.rs
|
|
50
53
|
- src/client.rs
|
|
51
54
|
- src/client/body.rs
|
|
52
55
|
- src/client/body/form.rs
|