webmock 3.22.0 → 3.23.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 +6 -1
- data/README.md +1 -1
- data/lib/webmock/http_lib_adapters/http_rb/response.rb +30 -12
- data/lib/webmock/http_lib_adapters/http_rb_adapter.rb +5 -5
- 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: 8a2d1add2b84d303329a722f0c7e9643f237949d0dc471ea1678021324cd41b4
|
4
|
+
data.tar.gz: e00640f1b7664959922011ae2f7b922811d94be4fb1bea90a988f3cca83486bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87f797196dedde96873a3740234d33f799745df144953ccfc36403ca6fbe4bd239f5f05818eb7cec25730823c2f99f83a1f42b79cf977b5672d720ed02bb3495
|
7
|
+
data.tar.gz: af708a4202382fb1a55c90a7f2c14b1a9d9b277bc8c4ee898dd31b712162bee4e9fb1fb6dd2931c1e39123eee8f15545db9fcd198ea5751f746be7eabfad33eb
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
# 3.23.0
|
4
|
+
|
5
|
+
* Fixed HTTP.rb adapter to support streaming real responses when WebMock is enabled.
|
6
|
+
|
7
|
+
Thanks to [Viacheslav Nepomniashchikh](https://github.com/aka-nez) for reporting and investigating this [issue](https://github.com/bblimke/webmock/issues/1017).
|
8
|
+
|
3
9
|
# 3.22.0
|
4
10
|
|
5
11
|
* 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
12
|
|
7
|
-
|
8
13
|
# 3.21.2
|
9
14
|
|
10
15
|
* 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.
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
WebMock
|
2
2
|
=======
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/webmock.svg)](http://badge.fury.io/rb/webmock)
|
4
|
-
[![Build Status](https://github.com/bblimke/webmock/workflows/CI/badge.svg?branch=master)](https://github.com/bblimke/webmock/actions)
|
4
|
+
[![Build Status](https://github.com/bblimke/webmock/actions/workflows/CI.yml/badge.svg?branch=master)](https://github.com/bblimke/webmock/actions)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/bblimke/webmock/badges/gpa.svg)](https://codeclimate.com/github/bblimke/webmock)
|
6
6
|
[![Mentioned in Awesome Ruby](https://awesome.re/mentioned-badge.svg)](https://github.com/markets/awesome-ruby)
|
7
7
|
|
@@ -6,9 +6,19 @@ module HTTP
|
|
6
6
|
webmock_response = ::WebMock::Response.new
|
7
7
|
|
8
8
|
webmock_response.status = [status.to_i, reason]
|
9
|
+
|
9
10
|
webmock_response.body = body.to_s
|
10
|
-
|
11
|
+
# This call is used to reset the body of the response to enable it to be streamed if necessary.
|
12
|
+
# The `body.to_s` call above reads the body, which allows WebMock to trigger any registered callbacks.
|
13
|
+
# However, once the body is read to_s, it cannot be streamed again and attempting to do so
|
14
|
+
# will raise a "HTTP::StateError: body has already been consumed" error.
|
15
|
+
# To avoid this error, we replace the original body with a new one.
|
16
|
+
# The new body has its @stream attribute set to new Streamer, instead of the original Connection.
|
17
|
+
# Unfortunately, it's not possible to reset the original body to its initial streaming state.
|
18
|
+
# Therefore, this replacement is the best workaround currently available.
|
19
|
+
reset_body_to_allow_it_to_be_streamed!(webmock_response)
|
11
20
|
|
21
|
+
webmock_response.headers = headers.to_h
|
12
22
|
webmock_response
|
13
23
|
end
|
14
24
|
|
@@ -21,16 +31,7 @@ module HTTP
|
|
21
31
|
# HTTP.rb 3.0+ uses a keyword argument to pass the encoding, but 1.x
|
22
32
|
# and 2.x use a positional argument, and 0.x don't support supplying
|
23
33
|
# the encoding.
|
24
|
-
body =
|
25
|
-
Body.new(Streamer.new(webmock_response.body))
|
26
|
-
elsif HTTP::VERSION < "3.0.0"
|
27
|
-
Body.new(Streamer.new(webmock_response.body), webmock_response.body.encoding)
|
28
|
-
else
|
29
|
-
Body.new(
|
30
|
-
Streamer.new(webmock_response.body, encoding: webmock_response.body.encoding),
|
31
|
-
encoding: webmock_response.body.encoding
|
32
|
-
)
|
33
|
-
end
|
34
|
+
body = build_http_rb_response_body_from_webmock_response(webmock_response)
|
34
35
|
|
35
36
|
return new(status, "1.1", headers, body, uri) if HTTP::VERSION < "1.0.0"
|
36
37
|
|
@@ -54,7 +55,18 @@ module HTTP
|
|
54
55
|
})
|
55
56
|
end
|
56
57
|
|
57
|
-
|
58
|
+
def build_http_rb_response_body_from_webmock_response(webmock_response)
|
59
|
+
if HTTP::VERSION < "1.0.0"
|
60
|
+
Body.new(Streamer.new(webmock_response.body))
|
61
|
+
elsif HTTP::VERSION < "3.0.0"
|
62
|
+
Body.new(Streamer.new(webmock_response.body), webmock_response.body.encoding)
|
63
|
+
else
|
64
|
+
Body.new(
|
65
|
+
Streamer.new(webmock_response.body, encoding: webmock_response.body.encoding),
|
66
|
+
encoding: webmock_response.body.encoding
|
67
|
+
)
|
68
|
+
end
|
69
|
+
end
|
58
70
|
|
59
71
|
def normalize_uri(uri)
|
60
72
|
return unless uri
|
@@ -65,5 +77,11 @@ module HTTP
|
|
65
77
|
uri
|
66
78
|
end
|
67
79
|
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def reset_body_to_allow_it_to_be_streamed!(webmock_response)
|
84
|
+
@body = self.class.build_http_rb_response_body_from_webmock_response(webmock_response)
|
85
|
+
end
|
68
86
|
end
|
69
87
|
end
|
@@ -31,9 +31,9 @@ if defined?(HTTP) && defined?(HTTP::VERSION)
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
require_relative "http_rb/client"
|
35
|
+
require_relative "http_rb/request"
|
36
|
+
require_relative "http_rb/response"
|
37
|
+
require_relative "http_rb/streamer"
|
38
|
+
require_relative "http_rb/webmock"
|
39
39
|
end
|
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.23.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-25 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.23.0/CHANGELOG.md
|
375
|
+
documentation_uri: https://www.rubydoc.info/gems/webmock/3.23.0
|
376
|
+
source_code_uri: https://github.com/bblimke/webmock/tree/v3.23.0
|
377
377
|
wiki_uri: https://github.com/bblimke/webmock/wiki
|
378
378
|
post_install_message:
|
379
379
|
rdoc_options: []
|