webmock 3.14.0 → 3.19.1

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.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +124 -2
  3. data/README.md +46 -18
  4. data/lib/webmock/api.rb +2 -0
  5. data/lib/webmock/assertion_failure.rb +2 -0
  6. data/lib/webmock/callback_registry.rb +2 -0
  7. data/lib/webmock/config.rb +2 -0
  8. data/lib/webmock/cucumber.rb +2 -0
  9. data/lib/webmock/deprecation.rb +2 -0
  10. data/lib/webmock/errors.rb +2 -0
  11. data/lib/webmock/http_lib_adapters/async_http_client_adapter.rb +8 -1
  12. data/lib/webmock/http_lib_adapters/curb_adapter.rb +4 -2
  13. data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +14 -6
  14. data/lib/webmock/http_lib_adapters/excon_adapter.rb +2 -0
  15. data/lib/webmock/http_lib_adapters/http_lib_adapter.rb +2 -0
  16. data/lib/webmock/http_lib_adapters/http_lib_adapter_registry.rb +2 -0
  17. data/lib/webmock/http_lib_adapters/http_rb/client.rb +3 -3
  18. data/lib/webmock/http_lib_adapters/http_rb/request.rb +3 -1
  19. data/lib/webmock/http_lib_adapters/http_rb/response.rb +6 -1
  20. data/lib/webmock/http_lib_adapters/http_rb/streamer.rb +6 -2
  21. data/lib/webmock/http_lib_adapters/http_rb/webmock.rb +8 -2
  22. data/lib/webmock/http_lib_adapters/http_rb_adapter.rb +2 -0
  23. data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +2 -0
  24. data/lib/webmock/http_lib_adapters/manticore_adapter.rb +2 -0
  25. data/lib/webmock/http_lib_adapters/net_http.rb +24 -115
  26. data/lib/webmock/http_lib_adapters/net_http_response.rb +2 -0
  27. data/lib/webmock/http_lib_adapters/patron_adapter.rb +2 -0
  28. data/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +2 -0
  29. data/lib/webmock/matchers/any_arg_matcher.rb +2 -0
  30. data/lib/webmock/matchers/hash_argument_matcher.rb +2 -0
  31. data/lib/webmock/matchers/hash_excluding_matcher.rb +2 -0
  32. data/lib/webmock/matchers/hash_including_matcher.rb +2 -0
  33. data/lib/webmock/minitest.rb +2 -0
  34. data/lib/webmock/rack_response.rb +2 -0
  35. data/lib/webmock/request_body_diff.rb +2 -0
  36. data/lib/webmock/request_execution_verifier.rb +2 -0
  37. data/lib/webmock/request_pattern.rb +26 -8
  38. data/lib/webmock/request_registry.rb +2 -0
  39. data/lib/webmock/request_signature.rb +4 -2
  40. data/lib/webmock/request_signature_snippet.rb +2 -0
  41. data/lib/webmock/request_stub.rb +34 -0
  42. data/lib/webmock/response.rb +10 -8
  43. data/lib/webmock/responses_sequence.rb +2 -0
  44. data/lib/webmock/rspec/matchers/request_pattern_matcher.rb +2 -0
  45. data/lib/webmock/rspec/matchers/webmock_matcher.rb +2 -0
  46. data/lib/webmock/rspec/matchers.rb +2 -0
  47. data/lib/webmock/rspec.rb +2 -0
  48. data/lib/webmock/stub_registry.rb +2 -0
  49. data/lib/webmock/stub_request_snippet.rb +2 -0
  50. data/lib/webmock/test_unit.rb +2 -0
  51. data/lib/webmock/util/hash_counter.rb +12 -6
  52. data/lib/webmock/util/hash_keys_stringifier.rb +2 -0
  53. data/lib/webmock/util/hash_validator.rb +2 -0
  54. data/lib/webmock/util/headers.rb +22 -8
  55. data/lib/webmock/util/json.rb +2 -0
  56. data/lib/webmock/util/query_mapper.rb +2 -0
  57. data/lib/webmock/util/uri.rb +3 -1
  58. data/lib/webmock/util/values_stringifier.rb +2 -0
  59. data/lib/webmock/util/version_checker.rb +7 -5
  60. data/lib/webmock/version.rb +3 -1
  61. data/lib/webmock/webmock.rb +12 -0
  62. data/lib/webmock.rb +2 -0
  63. metadata +51 -183
  64. data/.gemtest +0 -0
  65. data/.github/workflows/CI.yml +0 -37
  66. data/.gitignore +0 -34
  67. data/.rspec-tm +0 -2
  68. data/Gemfile +0 -9
  69. data/Rakefile +0 -38
  70. data/minitest/test_helper.rb +0 -34
  71. data/minitest/test_webmock.rb +0 -9
  72. data/minitest/webmock_spec.rb +0 -60
  73. data/spec/acceptance/async_http_client/async_http_client_spec.rb +0 -375
  74. data/spec/acceptance/async_http_client/async_http_client_spec_helper.rb +0 -73
  75. data/spec/acceptance/curb/curb_spec.rb +0 -499
  76. data/spec/acceptance/curb/curb_spec_helper.rb +0 -147
  77. data/spec/acceptance/em_http_request/em_http_request_spec.rb +0 -462
  78. data/spec/acceptance/em_http_request/em_http_request_spec_helper.rb +0 -77
  79. data/spec/acceptance/excon/excon_spec.rb +0 -77
  80. data/spec/acceptance/excon/excon_spec_helper.rb +0 -52
  81. data/spec/acceptance/http_rb/http_rb_spec.rb +0 -93
  82. data/spec/acceptance/http_rb/http_rb_spec_helper.rb +0 -54
  83. data/spec/acceptance/httpclient/httpclient_spec.rb +0 -217
  84. data/spec/acceptance/httpclient/httpclient_spec_helper.rb +0 -57
  85. data/spec/acceptance/manticore/manticore_spec.rb +0 -107
  86. data/spec/acceptance/manticore/manticore_spec_helper.rb +0 -35
  87. data/spec/acceptance/net_http/net_http_shared.rb +0 -153
  88. data/spec/acceptance/net_http/net_http_spec.rb +0 -369
  89. data/spec/acceptance/net_http/net_http_spec_helper.rb +0 -64
  90. data/spec/acceptance/net_http/real_net_http_spec.rb +0 -20
  91. data/spec/acceptance/patron/patron_spec.rb +0 -125
  92. data/spec/acceptance/patron/patron_spec_helper.rb +0 -54
  93. data/spec/acceptance/shared/allowing_and_disabling_net_connect.rb +0 -313
  94. data/spec/acceptance/shared/callbacks.rb +0 -148
  95. data/spec/acceptance/shared/complex_cross_concern_behaviors.rb +0 -36
  96. data/spec/acceptance/shared/enabling_and_disabling_webmock.rb +0 -95
  97. data/spec/acceptance/shared/precedence_of_stubs.rb +0 -15
  98. data/spec/acceptance/shared/request_expectations.rb +0 -930
  99. data/spec/acceptance/shared/returning_declared_responses.rb +0 -409
  100. data/spec/acceptance/shared/stubbing_requests.rb +0 -678
  101. data/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb +0 -135
  102. data/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb +0 -60
  103. data/spec/acceptance/webmock_shared.rb +0 -41
  104. data/spec/fixtures/test.txt +0 -1
  105. data/spec/quality_spec.rb +0 -84
  106. data/spec/spec_helper.rb +0 -48
  107. data/spec/support/example_curl_output.txt +0 -22
  108. data/spec/support/failures.rb +0 -9
  109. data/spec/support/my_rack_app.rb +0 -53
  110. data/spec/support/network_connection.rb +0 -19
  111. data/spec/support/webmock_server.rb +0 -70
  112. data/spec/unit/api_spec.rb +0 -175
  113. data/spec/unit/errors_spec.rb +0 -129
  114. data/spec/unit/http_lib_adapters/http_lib_adapter_registry_spec.rb +0 -17
  115. data/spec/unit/http_lib_adapters/http_lib_adapter_spec.rb +0 -12
  116. data/spec/unit/matchers/hash_excluding_matcher_spec.rb +0 -61
  117. data/spec/unit/matchers/hash_including_matcher_spec.rb +0 -87
  118. data/spec/unit/rack_response_spec.rb +0 -112
  119. data/spec/unit/request_body_diff_spec.rb +0 -90
  120. data/spec/unit/request_execution_verifier_spec.rb +0 -208
  121. data/spec/unit/request_pattern_spec.rb +0 -736
  122. data/spec/unit/request_registry_spec.rb +0 -95
  123. data/spec/unit/request_signature_snippet_spec.rb +0 -89
  124. data/spec/unit/request_signature_spec.rb +0 -155
  125. data/spec/unit/request_stub_spec.rb +0 -199
  126. data/spec/unit/response_spec.rb +0 -286
  127. data/spec/unit/stub_registry_spec.rb +0 -103
  128. data/spec/unit/stub_request_snippet_spec.rb +0 -115
  129. data/spec/unit/util/hash_counter_spec.rb +0 -39
  130. data/spec/unit/util/hash_keys_stringifier_spec.rb +0 -27
  131. data/spec/unit/util/headers_spec.rb +0 -28
  132. data/spec/unit/util/json_spec.rb +0 -33
  133. data/spec/unit/util/query_mapper_spec.rb +0 -157
  134. data/spec/unit/util/uri_spec.rb +0 -371
  135. data/spec/unit/util/version_checker_spec.rb +0 -65
  136. data/spec/unit/webmock_spec.rb +0 -60
  137. data/test/http_request.rb +0 -24
  138. data/test/shared_test.rb +0 -108
  139. data/test/test_helper.rb +0 -23
  140. data/test/test_webmock.rb +0 -12
  141. data/webmock.gemspec +0 -54
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8f150fbeccca419468dfebe632e3b5d365cb8c2df9a5e2a31e65591298786fb
4
- data.tar.gz: d92950bc5ae3510e599c40545f3e7a0ebaafa54a698f79a3c82243e240d35948
3
+ metadata.gz: 379567500380d6df66bea0edab72f977ddbcab8fc2cc79f9c2e4c535c46cfeb4
4
+ data.tar.gz: fbab14a1e3a2d7a5563f293e735f521dc47481e7d574f4ace0e5cefa9a15fb8e
5
5
  SHA512:
6
- metadata.gz: f58d569f7c633d758cee725e5dafb39edacb74e0017ba9c29de0cad8fe16d1f7740cc30847a9f129f6571232d2ca8172d7fb76a1eb3383e31ee8371472f141f9
7
- data.tar.gz: 52191c4e12ac3bf79b575f36d58823ea37ab17f83c7a62602889f361eafadabfa4b0b8ffc1f466eee6de53ea77578fc0149a60e14abdd8a7459b651afbeb85d0
6
+ metadata.gz: 768bc4817766c1b5d2c799c8453bf59411d69f36c4d3b6dfc0630f2a830efa4b72b78dd999cce146bf8f4754a05fbd0dbbddcc72a7389f8b48b8546d4d98dba0
7
+ data.tar.gz: ca14f9cffef86ef82b52985f5ad58f662cbffcb33b86050ffd6e9390efaf5892eed0469595f153d7b0d8a8e6141a75a1e47cdd8076178385a92fe99593c8b3c3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,127 @@
1
1
  # Changelog
2
2
 
3
+ # 3.19.0
4
+
5
+ * When passing a Proc or lambda as response body to `to_return_json`, the body is evaluated at the time of request and not at the time of `to_return_json` method invocation.
6
+
7
+ Thanks to [Jason Karns](https://github.com/jasonkarns) for reporting.
8
+
9
+ * Do not alter real (non-stubbed) request headers when handling em-http-request requests.
10
+
11
+ Thanks to [Yoann Lecuyer](https://github.com/ylecuyer)
12
+
13
+ * Fix matching stubs with HashExcludingMatcher
14
+
15
+ Thanks to [Lucas Arnaud](https://github.com/lucasarnaud)
16
+
17
+ * Remove development and test files from the gem package
18
+
19
+ Thanks to [Orien Madgwick](https://github.com/orien)
20
+
21
+ * Fix supported http client gem version checks.
22
+
23
+ Thanks to [Marc Rohloff](https://github.com/marcrohloff) and [Roman Stražanec](https://github.com/romanstrazanec)
24
+
25
+ * Non-string body passed to #to_return_json is now converted to JSON string.
26
+
27
+ Thanks to [inkstak](https://github.com/inkstak)
28
+
29
+ * `[::1]` is recognised as localhost e.g when passing `allow_localhost` option to `disable_net_connect!`
30
+
31
+ Thanks to [Yuki Inoue](https://github.com/Yuki-Inoue)
32
+
33
+ * Optimized `normalize_headers` for performance
34
+
35
+ Thanks to [Brandon Weaver](https://github.com/baweaver)
36
+
37
+ * Added Frozen string literal to files to optimise memory usage
38
+
39
+ Thanks to [Josh Nichols](https://github.com/technicalpickles)
40
+
41
+ # 3.18.1
42
+
43
+ * Reverted simplified connection handing in Net::HTTP adapter due to https://github.com/bblimke/webmock/issues/999
44
+
45
+ # 3.18.0
46
+
47
+ * Net::BufferedIO is not replaced anymore.
48
+
49
+ Thanks to [Ray Zane](https://github.com/rzane)
50
+
51
+ * Simplified connection handing in Net::HTTP adapter.
52
+
53
+ Thanks to [Ray Zane](https://github.com/rzane)
54
+
55
+ # 3.17.1
56
+
57
+ * Fixed Syntax Error
58
+
59
+ Thanks to [Mark Spangler](https://github.com/mspangler)
60
+
61
+ # 3.17.0
62
+
63
+ * Minimum required Ruby version is 2.3
64
+
65
+ Thanks to [Go Sueyoshi](https://github.com/sue445)
66
+
67
+ * When using Net::HTTP, stubbed socket StubSocket#close and StubSocket#closed? behave more like the real sockets.
68
+
69
+ Thanks to [Ray Zane](https://github.com/rzane)
70
+
71
+ * Added `peeraddr`, `ssl_version` and `cipher` methods to stubbed sockets used by Net::HTTP.
72
+
73
+ Thanks to [Ray Zane](https://github.com/rzane)
74
+
75
+ * Added support for matching top-level array in JSON request body.
76
+
77
+ E.g.
78
+
79
+ ````
80
+ stub_request(:post, 'www.example.com').with(body: [{a: 1}])
81
+ ````
82
+
83
+ Thanks to [Cedric Sohrauer](https://github.com/cedrics)
84
+
85
+ # 3.16.2
86
+
87
+ * Minimum required Ruby version is 2.0.
88
+
89
+ # 3.16.0 (yanked)
90
+
91
+ * Fix leaky file descriptors and reuse socket for persistent connections.
92
+
93
+ Thanks to [Ray Zane](https://github.com/rzane)
94
+
95
+ * Allow specifying for what URIs or hosts, Net::HTTP should connect on start.
96
+
97
+ Thanks to [Ray Zane](https://github.com/rzane)
98
+
99
+ # 3.15.2
100
+
101
+ * Minimum required Ruby version is 2.0.
102
+
103
+ # 3.15.0 (yanked)
104
+
105
+ * fixed async-http adapter on Windows
106
+
107
+ Thanks to [Pavel Rosický](https://github.com/ahorek)
108
+
109
+ * Support for http.rb >= 5.0.2
110
+
111
+ Thanks to [ojab](https://github.com/ojab)
112
+
113
+ * Curb adapter supports headers with `:` character in the header value
114
+
115
+ Thanks to [Giorgio Gambino](https://github.com/mrbuzz)
116
+
117
+ * Support for matching body of JSON or application/x-www-form-urlencoded requests with content type header including charset.
118
+
119
+ Thanks to [Timmitry](https://github.com/Timmitry)
120
+
121
+ * Prevent double-wrapping http.rb features on non-stubbed requests
122
+
123
+ Thanks to [Michael Fairley](https://github.com/michaelfairley)
124
+
3
125
  # 3.14.0
4
126
 
5
127
  * Bump Addressable from 2.3.6 to 2.8.0
@@ -605,9 +727,9 @@
605
727
  * `WebMock.disable_net_connect` accepts `:allow` option with an object that responds to `#call`, receiving a `URI` object and returning a boolean:
606
728
 
607
729
 
608
- blacklist = ['google.com', 'facebook.com', 'apple.com']
730
+ denylist = ['google.com', 'facebook.com', 'apple.com']
609
731
  allowed_sites = lambda{|uri|
610
- blacklist.none?{|site| uri.host.include?(site) }
732
+ denylist.none?{|site| uri.host.include?(site) }
611
733
  }
612
734
  WebMock.disable_net_connect!(:allow => allowed_sites)
613
735
 
data/README.md CHANGED
@@ -4,8 +4,6 @@ WebMock
4
4
  [![Build Status](https://github.com/bblimke/webmock/workflows/CI/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
- [![Inline docs](http://inch-ci.org/github/bblimke/webmock.svg?branch=master)](http://inch-ci.org/github/bblimke/webmock)
8
- [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=webmock&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=webmock&package-manager=bundler&version-scheme=semver)
9
7
 
10
8
  Library for stubbing and setting expectations on HTTP requests in Ruby.
11
9
 
@@ -40,32 +38,34 @@ Supported HTTP libraries
40
38
 
41
39
  Supported Ruby Interpreters
42
40
  ---------------------------
43
-
44
- * MRI 2.5
45
41
  * MRI 2.6
46
42
  * MRI 2.7
43
+ * MRI 3.0
44
+ * MRI 3.1
45
+ * MRI 3.2
47
46
  * JRuby
48
- * Rubinius
49
47
 
50
48
  ## Installation
51
49
 
52
50
  ```bash
53
- gem install webmock
51
+ gem install webmock
54
52
  ```
55
53
  or alternatively:
56
54
 
57
55
  ```ruby
58
- # add to your Gemfile
59
- group :test do
60
- gem "webmock"
61
- end
56
+ # add to your Gemfile
57
+ group :test do
58
+ gem "webmock"
59
+ end
62
60
  ```
63
61
 
64
62
  ### or to install the latest development version from github master
65
63
 
66
- git clone http://github.com/bblimke/webmock.git
67
- cd webmock
68
- rake install
64
+ ```bash
65
+ git clone http://github.com/bblimke/webmock.git
66
+ cd webmock
67
+ rake install
68
+ ```
69
69
 
70
70
  ## Upgrading from v1.x to v2.x
71
71
 
@@ -330,6 +330,16 @@ stub_request(:any, "www.example.com").
330
330
  Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
331
331
  ```
332
332
 
333
+ ### Response with JSON body
334
+
335
+ ```ruby
336
+
337
+ stub_request(:any, "www.example.com").
338
+ to_return_json(body: {foo: "bar"})
339
+
340
+ Net::HTTP.get('www.example.com', '/') # ===> "{\"foo\": \"bar\"}"
341
+ ```
342
+
333
343
  ### Response with custom status message
334
344
 
335
345
  ```ruby
@@ -383,7 +393,8 @@ RestClient.post('www.example.net', 'abc') # ===> "abc\n"
383
393
 
384
394
  ### Dynamically evaluated raw responses recorded with `curl -is`
385
395
 
386
- `curl -is www.example.com > /tmp/www.example.com.txt`
396
+ `curl -is www.example.com > /tmp/www.example.com.txt`
397
+
387
398
  ```ruby
388
399
  stub_request(:get, "www.example.com").
389
400
  to_return(lambda { |request| File.new("/tmp/#{request.uri.host.to_s}.txt") })
@@ -540,7 +551,7 @@ RestClient.get('www.example.org:8080', '/') # ===> Allowed
540
551
  With a `Regexp` matching the URI:
541
552
 
542
553
  ```ruby
543
- WebMock.disable_net_connect!(allow: %r{ample.org/foo})
554
+ WebMock.disable_net_connect!(allow: %r{ample\.org/foo})
544
555
 
545
556
  RestClient.get('www.example.org', '/foo/bar') # ===> Allowed
546
557
  RestClient.get('sample.org', '/foo') # ===> Allowed
@@ -550,9 +561,9 @@ RestClient.get('sample.org', '/bar') # ===> Failure
550
561
  With an object that responds to `#call`, receiving a `URI` object and returning a boolean:
551
562
 
552
563
  ```ruby
553
- blacklist = ['google.com', 'facebook.com', 'apple.com']
564
+ denylist = ['google.com', 'facebook.com', 'apple.com']
554
565
  allowed_sites = lambda{|uri|
555
- blacklist.none?{|site| uri.host.include?(site) }
566
+ denylist.none?{|site| uri.host.include?(site) }
556
567
  }
557
568
  WebMock.disable_net_connect!(allow: allowed_sites)
558
569
 
@@ -1161,13 +1172,30 @@ People who submitted patches and new features or suggested improvements. Many th
1161
1172
  * Alex Vondrak
1162
1173
  * Will Storey
1163
1174
  * Eduardo Hernandez
1175
+ * ojab
1176
+ * Giorgio Gambino
1177
+ * Timmitry
1178
+ * Michael Fairley
1179
+ * Ray Zane
1180
+ * Go Sueyoshi
1181
+ * Cedric Sohrauer
1182
+ * Akira Matsuda
1183
+ * Mark Spangler
1184
+ * Henrik Nyh
1185
+ * Yoann Lecuyer
1186
+ * Lucas Arnaud
1187
+ * Marc Rohloff
1188
+ * inkstak
1189
+ * Yuki Inoue
1190
+ * Brandon Weaver
1191
+ * Josh Nichols
1164
1192
 
1165
1193
  For a full list of contributors you can visit the
1166
1194
  [contributors](https://github.com/bblimke/webmock/contributors) page.
1167
1195
 
1168
1196
  ## Background
1169
1197
 
1170
- Thank you Fakeweb! This library was inspired by [FakeWeb](http://fakeweb.rubyforge.org).
1198
+ Thank you Fakeweb! This library was inspired by [FakeWeb](https://github.com/chrisk/fakeweb).
1171
1199
  I imported some solutions from that project to WebMock. I also copied some code i.e Net:HTTP adapter.
1172
1200
  Fakeweb architecture unfortunately didn't allow me to extend it easily with the features I needed.
1173
1201
  I also preferred some things to work differently i.e request stub precedence.
data/lib/webmock/api.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebMock
2
4
  module API
3
5
  extend self
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebMock
2
4
  class AssertionFailure
3
5
  @error_class = RuntimeError
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebMock
2
4
  class CallbackRegistry
3
5
  @@callbacks = []
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebMock
2
4
  class Config
3
5
  include Singleton
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'webmock'
2
4
  require 'webmock/rspec/matchers'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebMock
2
4
  class Deprecation
3
5
  class << self
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebMock
2
4
 
3
5
  class NetConnectNotAllowedError < Exception
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require 'async'
3
5
  require 'async/http'
@@ -151,7 +153,12 @@ if defined?(Async::HTTP)
151
153
  private
152
154
 
153
155
  def create_connected_sockets
154
- Async::IO::Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM).tap do |sockets|
156
+ pair = begin
157
+ Async::IO::Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)
158
+ rescue Errno::EAFNOSUPPORT
159
+ Async::IO::Socket.pair(Socket::AF_INET, Socket::SOCK_STREAM)
160
+ end
161
+ pair.tap do |sockets|
155
162
  sockets.each do |socket|
156
163
  socket.instance_variable_set :@alpn_protocol, nil
157
164
  socket.instance_eval do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require 'curb'
3
5
  rescue LoadError
@@ -5,7 +7,7 @@ rescue LoadError
5
7
  end
6
8
 
7
9
  if defined?(Curl)
8
- WebMock::VersionChecker.new('Curb', Curl::CURB_VERSION, '0.7.16', '0.9.1', ['0.8.7']).check_version!
10
+ WebMock::VersionChecker.new('Curb', Curl::CURB_VERSION, '0.7.16', '1.0.1', ['0.8.7']).check_version!
9
11
 
10
12
  module WebMock
11
13
  module HttpLibAdapters
@@ -128,7 +130,7 @@ if defined?(Curl)
128
130
  def headers_as_hash(headers)
129
131
  if headers.is_a?(Array)
130
132
  headers.inject({}) {|hash, header|
131
- name, value = header.split(":").map(&:strip)
133
+ name, value = header.split(":", 2).map(&:strip)
132
134
  hash[name] = value
133
135
  hash
134
136
  }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require 'em-http-request'
3
5
  rescue LoadError
@@ -101,7 +103,7 @@ if defined?(EventMachine::HttpClient)
101
103
 
102
104
  def connection_completed
103
105
  @state = :response_header
104
- send_request(request_signature.headers, request_signature.body)
106
+ send_request(*headers_and_body_processed_by_middleware)
105
107
  end
106
108
 
107
109
  def send_request(head, body)
@@ -168,12 +170,18 @@ if defined?(EventMachine::HttpClient)
168
170
  webmock_response
169
171
  end
170
172
 
171
- def build_request_signature
172
- headers, body = build_request, @req.body
173
-
174
- @conn.middleware.select {|m| m.respond_to?(:request) }.each do |m|
175
- headers, body = m.request(self, headers, body)
173
+ def headers_and_body_processed_by_middleware
174
+ @headers_and_body_processed_by_middleware ||= begin
175
+ head, body = build_request, @req.body
176
+ @conn.middleware.each do |m|
177
+ head, body = m.request(self, head, body) if m.respond_to?(:request)
178
+ end
179
+ [head, body]
176
180
  end
181
+ end
182
+
183
+ def build_request_signature
184
+ headers, body = headers_and_body_processed_by_middleware
177
185
 
178
186
  method = @req.method
179
187
  uri = @req.uri.clone
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require 'excon'
3
5
  rescue LoadError
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebMock
2
4
  class HttpLibAdapter
3
5
  def self.adapter_for(lib)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebMock
2
4
  class HttpLibAdapterRegistry
3
5
  include Singleton
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HTTP
2
4
  class Client
3
5
  alias_method :__perform__, :perform
@@ -5,9 +7,7 @@ module HTTP
5
7
  def perform(request, options)
6
8
  return __perform__(request, options) unless webmock_enabled?
7
9
 
8
- response = WebMockPerform.new(request) { __perform__(request, options) }.exec
9
- options.features.each { |_name, feature| response = feature.wrap_response(response) }
10
- response
10
+ WebMockPerform.new(request, options) { __perform__(request, options) }.exec
11
11
  end
12
12
 
13
13
  def webmock_enabled?
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HTTP
2
4
  class Request
3
5
  def webmock_signature
4
6
  request_body = if defined?(HTTP::Request::Body)
5
- ''.tap { |string| body.each { |part| string << part } }
7
+ String.new.tap { |string| body.each { |part| string << part } }
6
8
  else
7
9
  body
8
10
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HTTP
2
4
  class Response
3
5
  def to_webmock
@@ -24,7 +26,10 @@ module HTTP
24
26
  elsif HTTP::VERSION < "3.0.0"
25
27
  Body.new(Streamer.new(webmock_response.body), webmock_response.body.encoding)
26
28
  else
27
- Body.new(Streamer.new(webmock_response.body), encoding: webmock_response.body.encoding)
29
+ Body.new(
30
+ Streamer.new(webmock_response.body, encoding: webmock_response.body.encoding),
31
+ encoding: webmock_response.body.encoding
32
+ )
28
33
  end
29
34
 
30
35
  return new(status, "1.1", headers, body, uri) if HTTP::VERSION < "1.0.0"
@@ -1,8 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HTTP
2
4
  class Response
3
5
  class Streamer
4
- def initialize(str)
6
+ def initialize(str, encoding: Encoding::BINARY)
5
7
  @io = StringIO.new str
8
+ @encoding = encoding
6
9
  end
7
10
 
8
11
  def readpartial(size = nil, outbuf = nil)
@@ -14,7 +17,8 @@ module HTTP
14
17
  end
15
18
  end
16
19
 
17
- @io.read size, outbuf
20
+ chunk = @io.read size, outbuf
21
+ chunk.force_encoding(@encoding) if chunk
18
22
  end
19
23
 
20
24
  def close
@@ -1,7 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HTTP
2
4
  class WebMockPerform
3
- def initialize(request, &perform)
5
+ def initialize(request, options, &perform)
4
6
  @request = request
7
+ @options = options
5
8
  @perform = perform
6
9
  @request_signature = nil
7
10
  end
@@ -38,7 +41,10 @@ module HTTP
38
41
  webmock_response.raise_error_if_any
39
42
 
40
43
  invoke_callbacks(webmock_response, real_request: false)
41
- ::HTTP::Response.from_webmock @request, webmock_response, request_signature
44
+ response = ::HTTP::Response.from_webmock @request, webmock_response, request_signature
45
+
46
+ @options.features.each { |_name, feature| response = feature.wrap_response(response) }
47
+ response
42
48
  end
43
49
 
44
50
  def raise_timeout_error
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require "http"
3
5
  rescue LoadError
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require 'httpclient'
3
5
  require 'jsonclient' # defined in 'httpclient' gem as well
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require 'manticore'
3
5
  rescue LoadError