webmock 3.32.0 → 3.33.0
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/CHANGELOG.md +30 -0
- data/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +54 -26
- data/lib/webmock/util/uri.rb +2 -2
- data/lib/webmock/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 41c4be4a917d40c0448cdf920de152862f1ce887e379e49121020d506757c16d
|
|
4
|
+
data.tar.gz: 71ed3dc5e3df9671c7ce188fa579b86379ab365f95b666c7eeee7bf6851dc836
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 79843a07ef28cee5968bf6e3eb4b5eac10f688c3aba9caeb44cd30c74ec28ee8e0129eef69eab8d1a87e3991512b63c96589bbf52aaa912f12217ed86b20b4d2
|
|
7
|
+
data.tar.gz: '009710347fc3bf01b14ab050ba19c316af32a8a2803b0d40b3388be7ed824a5e6de371a860810df8ebff0de2dd588ad6071c876cf79a029835ccab32c8d48fe4'
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
# 3.33.0
|
|
4
|
+
|
|
5
|
+
* Return `effective_url` as a String for stubbed Typhoeus responses (#869)
|
|
6
|
+
|
|
7
|
+
Previously, this was an `Addressable::URI`. If your code calls methods such as `effective_url.host`, parse the returned string into a URI first.
|
|
8
|
+
|
|
9
|
+
The URL keeps the request's port, query order and encoding. It follows curl's formatting: for example, `http://example.com:80` becomes `http://example.com:80/`. Stubbed timeouts now provide an `effective_url` too.
|
|
10
|
+
|
|
11
|
+
Thanks to [Tom Brammar](https://github.com/tbrammar)
|
|
12
|
+
|
|
13
|
+
* Fix incorrect removal of default ports from displayed URLs
|
|
14
|
+
|
|
15
|
+
WebMock could accidentally remove `:80` or `:443` from a URL's path or query. For example, an error message could show `/foo/bar` instead of `/foo:80/bar`.
|
|
16
|
+
|
|
17
|
+
Only the host's default port is now removed. This also works when the port is immediately followed by a query string, as in `http://example.com:80?a=b`.
|
|
18
|
+
|
|
19
|
+
* Set `return_code` to `:ok` for completed stubbed Typhoeus requests (#736)
|
|
20
|
+
|
|
21
|
+
`return_code` is now `:ok` and `return_message` is now `"No error"`; both were previously `nil`. This includes HTTP error responses such as 404: `:ok` means the transfer completed. Stubbed timeouts still return `:operation_timedout`.
|
|
22
|
+
|
|
23
|
+
Thanks to [Michael Spiz](https://github.com/spizm)
|
|
24
|
+
|
|
25
|
+
* Fix the raw headers returned by stubbed Typhoeus responses
|
|
26
|
+
|
|
27
|
+
The `response_headers` string now uses the stubbed HTTP status. For example, a 404 stub no longer reports `HTTP/1.1 200 OK`.
|
|
28
|
+
|
|
29
|
+
Stubs without headers now return an empty `headers` hash (`{}`) instead of `nil`. Their `response_headers` contains the status line instead of being `nil`.
|
|
30
|
+
|
|
31
|
+
The raw headers use binary string encoding, matching real responses. For timeouts, `response_headers` is now an empty string.
|
|
32
|
+
|
|
3
33
|
# 3.32.0
|
|
4
34
|
|
|
5
35
|
* Make a `Net::HTTP` object created while WebMock was enabled behave like any other `Net::HTTP` object after `WebMock.disable!` (#1067)
|
|
@@ -52,8 +52,8 @@ if defined?(Typhoeus)
|
|
|
52
52
|
Typhoeus.on_complete.delete_if {|v| v == AFTER_REQUEST_CALLBACK }
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
-
def self.build_request_signature(req)
|
|
56
|
-
uri = WebMock::Util::URI.heuristic_parse(
|
|
55
|
+
def self.build_request_signature(req, url = req.url)
|
|
56
|
+
uri = WebMock::Util::URI.heuristic_parse(url)
|
|
57
57
|
uri.path = uri.normalized_path.gsub("[^:]//","/")
|
|
58
58
|
|
|
59
59
|
headers = req.options[:headers]
|
|
@@ -89,42 +89,69 @@ if defined?(Typhoeus)
|
|
|
89
89
|
webmock_response
|
|
90
90
|
end
|
|
91
91
|
|
|
92
|
-
def self.generate_typhoeus_response(
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
def self.generate_typhoeus_response(webmock_response, url)
|
|
93
|
+
response_options = if webmock_response.should_timeout
|
|
94
|
+
{
|
|
95
95
|
code: 0,
|
|
96
96
|
status_message: "",
|
|
97
97
|
body: "",
|
|
98
98
|
headers: {},
|
|
99
99
|
return_code: :operation_timedout,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
appconnect_time: 0.0,
|
|
103
|
-
pretransfer_time: 0.0,
|
|
104
|
-
connect_time: 0.0,
|
|
105
|
-
namelookup_time: 0.0,
|
|
106
|
-
redirect_time: 0.0
|
|
107
|
-
)
|
|
100
|
+
response_headers: ""
|
|
101
|
+
}
|
|
108
102
|
else
|
|
109
|
-
|
|
103
|
+
{
|
|
110
104
|
code: webmock_response.status[0],
|
|
111
105
|
status_message: webmock_response.status[1],
|
|
112
106
|
body: webmock_response.body,
|
|
113
107
|
headers: webmock_response.headers,
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
appconnect_time: 0.0,
|
|
118
|
-
pretransfer_time: 0.0,
|
|
119
|
-
connect_time: 0.0,
|
|
120
|
-
namelookup_time: 0.0,
|
|
121
|
-
redirect_time: 0.0
|
|
122
|
-
)
|
|
108
|
+
return_code: :ok,
|
|
109
|
+
response_headers: response_headers_string(webmock_response)
|
|
110
|
+
}
|
|
123
111
|
end
|
|
112
|
+
response = ::Typhoeus::Response.new(response_options.merge(
|
|
113
|
+
effective_url: effective_url(url),
|
|
114
|
+
total_time: 0.0,
|
|
115
|
+
starttransfer_time: 0.0,
|
|
116
|
+
appconnect_time: 0.0,
|
|
117
|
+
pretransfer_time: 0.0,
|
|
118
|
+
connect_time: 0.0,
|
|
119
|
+
namelookup_time: 0.0,
|
|
120
|
+
redirect_time: 0.0
|
|
121
|
+
))
|
|
124
122
|
response.mock = :webmock
|
|
125
123
|
response
|
|
126
124
|
end
|
|
127
125
|
|
|
126
|
+
# Without response_headers, Typhoeus builds them for a mocked response
|
|
127
|
+
# from its return_code, as in "HTTP/1.1 ok Mock Reason Phrase".
|
|
128
|
+
def self.response_headers_string(webmock_response)
|
|
129
|
+
code, reason = webmock_response.status
|
|
130
|
+
lines = ["HTTP/1.1 #{code} #{reason}"]
|
|
131
|
+
(webmock_response.headers || {}).each do |name, values|
|
|
132
|
+
Array(values).each { |value| lines << "#{name}: #{value}" }
|
|
133
|
+
end
|
|
134
|
+
# Bytes, as in a real response, so values in different encodings join.
|
|
135
|
+
lines.map(&:b).join("\r\n") + "\r\n\r\n"
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# The request URL as curl reports it: with its port, query and encoding as
|
|
139
|
+
# given, but with a lower case scheme, http:// when there is none, dot
|
|
140
|
+
# segments resolved, "/" for an empty path and no empty query or
|
|
141
|
+
# fragment. Like curl's, it is a binary string.
|
|
142
|
+
def self.effective_url(url)
|
|
143
|
+
# A scheme needs at least one slash after it, so localhost:3000 has
|
|
144
|
+
# none. heuristic_parse turns http:/ and http:/// into http://.
|
|
145
|
+
url = "http://#{url}" unless url.match?(%r{\A[a-z][a-z0-9+.\-]*:/}i)
|
|
146
|
+
uri = WebMock::Util::URI.heuristic_parse(url)
|
|
147
|
+
uri.scheme = uri.scheme.downcase
|
|
148
|
+
uri.path = Addressable::URI.normalize_path(uri.path)
|
|
149
|
+
uri.path = "/" if uri.path.empty?
|
|
150
|
+
uri.query = nil if uri.query == ""
|
|
151
|
+
uri.fragment = nil if uri.fragment == ""
|
|
152
|
+
uri.to_s.b
|
|
153
|
+
end
|
|
154
|
+
|
|
128
155
|
def self.request_hash(request_signature)
|
|
129
156
|
hash = {}
|
|
130
157
|
|
|
@@ -160,14 +187,15 @@ if defined?(Typhoeus)
|
|
|
160
187
|
res = true
|
|
161
188
|
|
|
162
189
|
unless WebMock::HttpLibAdapters::TyphoeusAdapter.disabled?
|
|
163
|
-
|
|
190
|
+
# Typhoeus builds a curl handle to work out the URL, so do it once.
|
|
191
|
+
url = request.url
|
|
192
|
+
request_signature = ::WebMock::HttpLibAdapters::TyphoeusAdapter.build_request_signature(request, url)
|
|
164
193
|
request.block_connection = false;
|
|
165
194
|
|
|
166
195
|
::WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)
|
|
167
196
|
|
|
168
197
|
if webmock_response = ::WebMock::StubRegistry.instance.response_for_request(request_signature)
|
|
169
|
-
|
|
170
|
-
response = ::WebMock::HttpLibAdapters::TyphoeusAdapter.generate_typhoeus_response(request_signature, webmock_response)
|
|
198
|
+
response = ::WebMock::HttpLibAdapters::TyphoeusAdapter.generate_typhoeus_response(webmock_response, url)
|
|
171
199
|
if request.respond_to?(:on_headers)
|
|
172
200
|
request.execute_headers_callbacks(response)
|
|
173
201
|
end
|
data/lib/webmock/util/uri.rb
CHANGED
|
@@ -58,8 +58,8 @@ module WebMock
|
|
|
58
58
|
|
|
59
59
|
def self.strip_default_port_from_uri_string(uri_string)
|
|
60
60
|
case uri_string
|
|
61
|
-
when %r{^http://} then uri_string.sub(%r{:80(
|
|
62
|
-
when %r{^https://} then uri_string.sub(%r{:443(
|
|
61
|
+
when %r{^http://} then uri_string.sub(%r{\A(http://[^/?#]+):80(?=[/?#]|\z)}, '\1')
|
|
62
|
+
when %r{^https://} then uri_string.sub(%r{\A(https://[^/?#]+):443(?=[/?#]|\z)}, '\1')
|
|
63
63
|
else uri_string
|
|
64
64
|
end
|
|
65
65
|
end
|
data/lib/webmock/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: webmock
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.33.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bartosz Blimke
|
|
@@ -360,9 +360,9 @@ licenses:
|
|
|
360
360
|
- MIT
|
|
361
361
|
metadata:
|
|
362
362
|
bug_tracker_uri: https://github.com/bblimke/webmock/issues
|
|
363
|
-
changelog_uri: https://github.com/bblimke/webmock/blob/v3.
|
|
364
|
-
documentation_uri: https://www.rubydoc.info/gems/webmock/3.
|
|
365
|
-
source_code_uri: https://github.com/bblimke/webmock/tree/v3.
|
|
363
|
+
changelog_uri: https://github.com/bblimke/webmock/blob/v3.33.0/CHANGELOG.md
|
|
364
|
+
documentation_uri: https://www.rubydoc.info/gems/webmock/3.33.0
|
|
365
|
+
source_code_uri: https://github.com/bblimke/webmock/tree/v3.33.0
|
|
366
366
|
wiki_uri: https://github.com/bblimke/webmock/wiki
|
|
367
367
|
rdoc_options: []
|
|
368
368
|
require_paths:
|