webmock 3.12.1 → 3.12.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9da0e1f9d2507b4f2e84fc1b4fb4dbe513daba94771af7a255199c1f93ac7cbf
4
- data.tar.gz: ddc87014539d9e40044c2039cd6a0f82d4da9e44035066481c7876e306322922
3
+ metadata.gz: 6cf9216e779a2041d66197b6842541c77cb4bbcccc93c5d1b1260283b1003264
4
+ data.tar.gz: '04926e981765e34e6c39919a14dc7f41ce7b7a272484762269adae18004902d0'
5
5
  SHA512:
6
- metadata.gz: feb255076779f8f3311238a2f86d3ac4aeac85d904b9ce7972f80df011cffaac9e63322267c8a71cb5ed692b9cbc40fed75dacc16a1a4a377376d4abb89e89d6
7
- data.tar.gz: e4e881fa8960506b5acec58312e2cd40d2fbc5f4f54487e8893713bba05459ca16b4ec0951c25aee2a239a885fb0a62637faf371b2eb46aca3e0d9ba0f5c1a94
6
+ metadata.gz: d0998bb9620479a4c3036ea2872ba8de5f0748b5cb4b62e454239324cdecede5007d7dd63e65ebc676f9798574ebf680255737623088a01293dbca7eaa95a1b2
7
+ data.tar.gz: 7afd145d161fe7460ad0ef10f4eb1ec29e67b58cd0462de7bfc5fac39fc210f9bd27f7d56b508ab8552be1152ec807245044ebe009cdca15b944fe58bdc9d679
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ # 3.12.2
4
+
5
+ * Fixed em-http-request adapter to avoid calling middleware twice.
6
+
7
+ Thanks to [Alex Vondrak](https://github.com/ajvondrak)
8
+
3
9
  # 3.12.1
4
10
 
5
11
  * Fixed handling of URIs with IPv6 addresses with square brackets when in Net::HTTP adapter.
data/README.md CHANGED
@@ -24,19 +24,19 @@ Features
24
24
  Supported HTTP libraries
25
25
  ------------------------
26
26
 
27
- * Async::HTTP::Client
28
- * Curb (currently only Curb::Easy)
29
- * EM-HTTP-Request
30
- * Excon
31
- * HTTPClient
27
+ * [Async::HTTP::Client](https://github.com/socketry/async-http)
28
+ * [Curb](https://github.com/taf2/curb) (currently only Curb::Easy)
29
+ * [EM-HTTP-Request](https://github.com/igrigorik/em-http-request)
30
+ * [Excon](https://github.com/excon/excon)
31
+ * [HTTPClient](https://github.com/nahi/httpclient)
32
32
  * [HTTP Gem (also known as http.rb)](https://github.com/httprb/http)
33
- * Manticore
34
- * Net::HTTP and other libraries based on Net::HTTP, e.g.:
35
- * HTTParty
36
- * REST Client
37
- * RightHttpConnection
38
- * Patron
39
- * Typhoeus (currently only Typhoeus::Hydra)
33
+ * [httpx](https://honeyryderchuck.gitlab.io/httpx/wiki/Webmock-Adapter)
34
+ * [Manticore](https://github.com/cheald/manticore)
35
+ * [Net::HTTP](https://ruby-doc.org/stdlib-2.7.0/libdoc/net/http/rdoc/Net/HTTP.html) and other libraries based on Net::HTTP, e.g.:
36
+ * [HTTParty](https://github.com/jnunemaker/httparty)
37
+ * [REST Client](https://github.com/rest-client/rest-client)
38
+ * [Patron](https://github.com/toland/patron)
39
+ * [Typhoeus](https://github.com/typhoeus/typhoeus) (currently only Typhoeus::Hydra)
40
40
 
41
41
  Supported Ruby Interpreters
42
42
  ---------------------------
@@ -1158,6 +1158,7 @@ People who submitted patches and new features or suggested improvements. Many th
1158
1158
  * Tony Schneider
1159
1159
  * Niklas Hösl
1160
1160
  * Johanna Hartmann
1161
+ * Alex Vondrak
1161
1162
 
1162
1163
  For a full list of contributors you can visit the
1163
1164
  [contributors](https://github.com/bblimke/webmock/contributors) page.
@@ -99,6 +99,11 @@ if defined?(EventMachine::HttpClient)
99
99
  end
100
100
  end
101
101
 
102
+ def connection_completed
103
+ @state = :response_header
104
+ send_request(request_signature.headers, request_signature.body)
105
+ end
106
+
102
107
  def send_request(head, body)
103
108
  WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)
104
109
 
@@ -164,7 +169,7 @@ if defined?(EventMachine::HttpClient)
164
169
  end
165
170
 
166
171
  def build_request_signature
167
- headers, body = @req.headers, @req.body
172
+ headers, body = build_request, @req.body
168
173
 
169
174
  @conn.middleware.select {|m| m.respond_to?(:request) }.each do |m|
170
175
  headers, body = m.request(self, headers, body)
@@ -178,8 +183,6 @@ if defined?(EventMachine::HttpClient)
178
183
 
179
184
  body = form_encode_body(body) if body.is_a?(Hash)
180
185
 
181
- headers = @req.headers
182
-
183
186
  if headers['authorization'] && headers['authorization'].is_a?(Array)
184
187
  headers['Authorization'] = WebMock::Util::Headers.basic_auth_header(headers.delete('authorization'))
185
188
  end
@@ -1,3 +1,3 @@
1
1
  module WebMock
2
- VERSION = '3.12.1' unless defined?(::WebMock::VERSION)
2
+ VERSION = '3.12.2' unless defined?(::WebMock::VERSION)
3
3
  end
@@ -71,6 +71,35 @@ unless RUBY_PLATFORM =~ /java/
71
71
  end
72
72
  end
73
73
 
74
+ it "only calls request middleware once" do
75
+ stub_request(:get, "www.example.com")
76
+
77
+ middleware = Class.new do
78
+ def self.called!
79
+ @called = called + 1
80
+ end
81
+
82
+ def self.called
83
+ @called || 0
84
+ end
85
+
86
+ def request(client, head, body)
87
+ self.class.called!
88
+ [head, body]
89
+ end
90
+ end
91
+
92
+ EM.run do
93
+ conn = EventMachine::HttpRequest.new('http://www.example.com/')
94
+ conn.use middleware
95
+ http = conn.get
96
+ http.callback do
97
+ expect(middleware.called).to eq(1)
98
+ EM.stop
99
+ end
100
+ end
101
+ end
102
+
74
103
  let(:response_middleware) do
75
104
  Class.new do
76
105
  def response(resp)
@@ -119,6 +148,33 @@ unless RUBY_PLATFORM =~ /java/
119
148
  context 'making a real request', net_connect: true do
120
149
  before { WebMock.allow_net_connect! }
121
150
  include_examples "em-http-request middleware/after_request hook integration"
151
+
152
+ it "only calls request middleware once" do
153
+ middleware = Class.new do
154
+ def self.called!
155
+ @called = called + 1
156
+ end
157
+
158
+ def self.called
159
+ @called || 0
160
+ end
161
+
162
+ def request(client, head, body)
163
+ self.class.called!
164
+ [head, body]
165
+ end
166
+ end
167
+
168
+ EM.run do
169
+ conn = EventMachine::HttpRequest.new(webmock_server_url)
170
+ conn.use middleware
171
+ http = conn.get
172
+ http.callback do
173
+ expect(middleware.called).to eq(1)
174
+ EM.stop
175
+ end
176
+ end
177
+ end
122
178
  end
123
179
 
124
180
  context 'when the request is stubbed' do
@@ -28,8 +28,8 @@ module PatronSpecHelper
28
28
  end
29
29
  end
30
30
 
31
- status_line_pattern = %r(\AHTTP/(\d+\.\d+)\s+(\d\d\d)\s*([^\r\n]+)?)
32
- message = response.status_line.match(status_line_pattern)[3] || ""
31
+ status_line_pattern = %r(\AHTTP/(\d+(\.\d+)?)\s+(\d\d\d)\s*([^\r\n]+)?)
32
+ message = response.status_line.match(status_line_pattern)[4] || ""
33
33
 
34
34
  OpenStruct.new({
35
35
  body: response.body,
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.12.1
4
+ version: 3.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bartosz Blimke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-05 00:00:00.000000000 Z
11
+ date: 2021-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -422,9 +422,9 @@ licenses:
422
422
  - MIT
423
423
  metadata:
424
424
  bug_tracker_uri: https://github.com/bblimke/webmock/issues
425
- changelog_uri: https://github.com/bblimke/webmock/blob/v3.12.1/CHANGELOG.md
426
- documentation_uri: https://www.rubydoc.info/gems/webmock/3.12.1
427
- source_code_uri: https://github.com/bblimke/webmock/tree/v3.12.1
425
+ changelog_uri: https://github.com/bblimke/webmock/blob/v3.12.2/CHANGELOG.md
426
+ documentation_uri: https://www.rubydoc.info/gems/webmock/3.12.2
427
+ source_code_uri: https://github.com/bblimke/webmock/tree/v3.12.2
428
428
  wiki_uri: https://github.com/bblimke/webmock/wiki
429
429
  post_install_message:
430
430
  rdoc_options: []