webmock 3.21.2 → 3.22.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +20 -21
- data/lib/webmock/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecff3692887f15d1f0e2e19df92093a40d4f6e5f7e4686d7e18ee4efaadf190f
|
4
|
+
data.tar.gz: 6cf4e165350b7878223e28687db13d57df6fe07d90f50a087527d5d001b305e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 566cf68fd9c0ee2de8c5e54693e0caa2b956c537f9b82362b7eb7547214349b7966029d6cf12dcac0ca930b0b0f9ad2c32c7dace3a2bd84d43eecd488b194144
|
7
|
+
data.tar.gz: a69faa775b378ee5108525cd431ab9bf242ac93afeb5fc351a7549aa852099fc9c84ceef4a6dccf265e7e27ed5e0894937a1abbc4fa9a641d9fb9c51c0e8ff90
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
# 3.22.0
|
4
|
+
|
5
|
+
* Addressed an issue in the HTTPClient adapter where memoized stubbed responses and memoized request_signatures were incorrectly persisted between subsequent requests ([#1019](https://github.com/bblimke/webmock/issues/1019)). The implementation of a more robust thread-safety solution by [Tom Beauvais](https://github.com/tbeauvais) in [PR #300](https://github.com/bblimke/webmock/pull/300) not only resolved the memoization problem but also enhanced the overall thread safety of the adapter. This update ensures that stubbed responses and request signatures are correctly isolated to individual requests, improving both consistency and thread safety.
|
6
|
+
|
7
|
+
|
3
8
|
# 3.21.2
|
4
9
|
|
5
10
|
* Corrected type checking in `WebMock::Response#assert_valid_body!` to accurately recognize `Hash` objects. Additionally, improved the clarity of the error message for unsupported body types, guiding users towards proper usage.
|
@@ -45,6 +45,8 @@ if defined?(::HTTPClient)
|
|
45
45
|
end
|
46
46
|
|
47
47
|
module WebMockHTTPClients
|
48
|
+
WEBMOCK_HTTPCLIENT_RESPONSES = :webmock_httpclient_responses
|
49
|
+
WEBMOCK_HTTPCLIENT_REQUEST_SIGNATURES = :webmock_httpclient_request_signatures
|
48
50
|
|
49
51
|
REQUEST_RESPONSE_LOCK = Mutex.new
|
50
52
|
|
@@ -57,12 +59,14 @@ if defined?(::HTTPClient)
|
|
57
59
|
end
|
58
60
|
|
59
61
|
def do_get(req, proxy, conn, stream = false, &block)
|
62
|
+
clear_thread_variables unless conn.async_thread
|
63
|
+
|
60
64
|
request_signature = build_request_signature(req, :reuse_existing)
|
61
65
|
|
62
66
|
WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)
|
63
67
|
|
64
68
|
if webmock_responses[request_signature]
|
65
|
-
webmock_response =
|
69
|
+
webmock_response = webmock_responses.delete(request_signature)
|
66
70
|
response = build_httpclient_response(webmock_response, stream, req.header, &block)
|
67
71
|
@request_filter.each do |filter|
|
68
72
|
filter.filter_response(req, response)
|
@@ -73,7 +77,7 @@ if defined?(::HTTPClient)
|
|
73
77
|
res
|
74
78
|
elsif WebMock.net_connect_allowed?(request_signature.uri)
|
75
79
|
# in case there is a nil entry in the hash...
|
76
|
-
|
80
|
+
webmock_responses.delete(request_signature)
|
77
81
|
|
78
82
|
res = if stream
|
79
83
|
do_get_stream_without_webmock(req, proxy, conn, &block)
|
@@ -103,12 +107,16 @@ if defined?(::HTTPClient)
|
|
103
107
|
end
|
104
108
|
|
105
109
|
def do_request_async(method, uri, query, body, extheader)
|
110
|
+
clear_thread_variables
|
106
111
|
req = create_request(method, uri, query, body, extheader)
|
107
112
|
request_signature = build_request_signature(req)
|
108
|
-
|
113
|
+
webmock_request_signatures << request_signature
|
109
114
|
|
110
115
|
if webmock_responses[request_signature] || WebMock.net_connect_allowed?(request_signature.uri)
|
111
|
-
super
|
116
|
+
conn = super
|
117
|
+
conn.async_thread[WEBMOCK_HTTPCLIENT_REQUEST_SIGNATURES] = Thread.current[WEBMOCK_HTTPCLIENT_REQUEST_SIGNATURES]
|
118
|
+
conn.async_thread[WEBMOCK_HTTPCLIENT_RESPONSES] = Thread.current[WEBMOCK_HTTPCLIENT_RESPONSES]
|
119
|
+
conn
|
112
120
|
else
|
113
121
|
raise WebMock::NetConnectNotAllowedError.new(request_signature)
|
114
122
|
end
|
@@ -188,22 +196,18 @@ if defined?(::HTTPClient)
|
|
188
196
|
end
|
189
197
|
|
190
198
|
def webmock_responses
|
191
|
-
|
192
|
-
|
193
|
-
hash[request_signature] = WebMock::StubRegistry.instance.response_for_request(request_signature)
|
194
|
-
end
|
199
|
+
Thread.current[WEBMOCK_HTTPCLIENT_RESPONSES] ||= Hash.new do |hash, request_signature|
|
200
|
+
hash[request_signature] = WebMock::StubRegistry.instance.response_for_request(request_signature)
|
195
201
|
end
|
196
202
|
end
|
197
203
|
|
198
204
|
def webmock_request_signatures
|
199
|
-
|
205
|
+
Thread.current[WEBMOCK_HTTPCLIENT_REQUEST_SIGNATURES] ||= []
|
200
206
|
end
|
201
207
|
|
202
208
|
def previous_signature_for(signature)
|
203
|
-
|
204
|
-
|
205
|
-
webmock_request_signatures.delete_at(index)
|
206
|
-
end
|
209
|
+
return nil unless index = webmock_request_signatures.index(signature)
|
210
|
+
webmock_request_signatures.delete_at(index)
|
207
211
|
end
|
208
212
|
|
209
213
|
private
|
@@ -219,14 +223,9 @@ if defined?(::HTTPClient)
|
|
219
223
|
end
|
220
224
|
end
|
221
225
|
|
222
|
-
def
|
223
|
-
|
224
|
-
|
225
|
-
else
|
226
|
-
REQUEST_RESPONSE_LOCK.synchronize do
|
227
|
-
yield
|
228
|
-
end
|
229
|
-
end
|
226
|
+
def clear_thread_variables
|
227
|
+
Thread.current[WEBMOCK_HTTPCLIENT_REQUEST_SIGNATURES] = nil
|
228
|
+
Thread.current[WEBMOCK_HTTPCLIENT_RESPONSES] = nil
|
230
229
|
end
|
231
230
|
end
|
232
231
|
|
data/lib/webmock/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webmock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.22.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bartosz Blimke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -371,9 +371,9 @@ licenses:
|
|
371
371
|
- MIT
|
372
372
|
metadata:
|
373
373
|
bug_tracker_uri: https://github.com/bblimke/webmock/issues
|
374
|
-
changelog_uri: https://github.com/bblimke/webmock/blob/v3.
|
375
|
-
documentation_uri: https://www.rubydoc.info/gems/webmock/3.
|
376
|
-
source_code_uri: https://github.com/bblimke/webmock/tree/v3.
|
374
|
+
changelog_uri: https://github.com/bblimke/webmock/blob/v3.22.0/CHANGELOG.md
|
375
|
+
documentation_uri: https://www.rubydoc.info/gems/webmock/3.22.0
|
376
|
+
source_code_uri: https://github.com/bblimke/webmock/tree/v3.22.0
|
377
377
|
wiki_uri: https://github.com/bblimke/webmock/wiki
|
378
378
|
post_install_message:
|
379
379
|
rdoc_options: []
|