mercadopago-custom-checkout 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +5 -5
  2. data/.gs/bin/rake +12 -8
  3. data/.gs/specifications/rake-10.5.0.gemspec +24 -28
  4. data/.tool-versions +1 -0
  5. data/lib/mercadopago/custom_checkout/version.rb +1 -1
  6. data/mercadopago-custom-checkout.gemspec +3 -3
  7. metadata +14 -125
  8. data/.gs/cache/faraday-0.9.2.gem +0 -0
  9. data/.gs/cache/minitest-5.9.0.gem +0 -0
  10. data/.gs/cache/multi_json-1.12.1.gem +0 -0
  11. data/.gs/cache/multipart-post-2.0.0.gem +0 -0
  12. data/.gs/gems/faraday-0.9.2/LICENSE.md +0 -20
  13. data/.gs/gems/faraday-0.9.2/README.md +0 -245
  14. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/em_http.rb +0 -237
  15. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/em_http_ssl_patch.rb +0 -56
  16. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/em_synchrony/parallel_manager.rb +0 -66
  17. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/em_synchrony.rb +0 -100
  18. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/excon.rb +0 -81
  19. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/httpclient.rb +0 -117
  20. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/net_http.rb +0 -130
  21. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/net_http_persistent.rb +0 -49
  22. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/patron.rb +0 -78
  23. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/rack.rb +0 -58
  24. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/test.rb +0 -162
  25. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter/typhoeus.rb +0 -123
  26. data/.gs/gems/faraday-0.9.2/lib/faraday/adapter.rb +0 -46
  27. data/.gs/gems/faraday-0.9.2/lib/faraday/autoload.rb +0 -84
  28. data/.gs/gems/faraday-0.9.2/lib/faraday/connection.rb +0 -437
  29. data/.gs/gems/faraday-0.9.2/lib/faraday/error.rb +0 -53
  30. data/.gs/gems/faraday-0.9.2/lib/faraday/middleware.rb +0 -37
  31. data/.gs/gems/faraday-0.9.2/lib/faraday/options.rb +0 -359
  32. data/.gs/gems/faraday-0.9.2/lib/faraday/parameters.rb +0 -197
  33. data/.gs/gems/faraday-0.9.2/lib/faraday/rack_builder.rb +0 -213
  34. data/.gs/gems/faraday-0.9.2/lib/faraday/request/authorization.rb +0 -42
  35. data/.gs/gems/faraday-0.9.2/lib/faraday/request/basic_authentication.rb +0 -13
  36. data/.gs/gems/faraday-0.9.2/lib/faraday/request/instrumentation.rb +0 -36
  37. data/.gs/gems/faraday-0.9.2/lib/faraday/request/multipart.rb +0 -63
  38. data/.gs/gems/faraday-0.9.2/lib/faraday/request/retry.rb +0 -154
  39. data/.gs/gems/faraday-0.9.2/lib/faraday/request/token_authentication.rb +0 -15
  40. data/.gs/gems/faraday-0.9.2/lib/faraday/request/url_encoded.rb +0 -36
  41. data/.gs/gems/faraday-0.9.2/lib/faraday/request.rb +0 -92
  42. data/.gs/gems/faraday-0.9.2/lib/faraday/response/logger.rb +0 -59
  43. data/.gs/gems/faraday-0.9.2/lib/faraday/response/raise_error.rb +0 -21
  44. data/.gs/gems/faraday-0.9.2/lib/faraday/response.rb +0 -93
  45. data/.gs/gems/faraday-0.9.2/lib/faraday/upload_io.rb +0 -67
  46. data/.gs/gems/faraday-0.9.2/lib/faraday/utils.rb +0 -309
  47. data/.gs/gems/faraday-0.9.2/lib/faraday.rb +0 -268
  48. data/.gs/gems/minitest-5.9.0/.autotest +0 -34
  49. data/.gs/gems/minitest-5.9.0/History.rdoc +0 -1176
  50. data/.gs/gems/minitest-5.9.0/Manifest.txt +0 -26
  51. data/.gs/gems/minitest-5.9.0/README.rdoc +0 -656
  52. data/.gs/gems/minitest-5.9.0/Rakefile +0 -72
  53. data/.gs/gems/minitest-5.9.0/design_rationale.rb +0 -52
  54. data/.gs/gems/minitest-5.9.0/lib/hoe/minitest.rb +0 -26
  55. data/.gs/gems/minitest-5.9.0/lib/minitest/assertions.rb +0 -674
  56. data/.gs/gems/minitest-5.9.0/lib/minitest/autorun.rb +0 -13
  57. data/.gs/gems/minitest-5.9.0/lib/minitest/benchmark.rb +0 -424
  58. data/.gs/gems/minitest-5.9.0/lib/minitest/expectations.rb +0 -284
  59. data/.gs/gems/minitest-5.9.0/lib/minitest/hell.rb +0 -17
  60. data/.gs/gems/minitest-5.9.0/lib/minitest/mock.rb +0 -232
  61. data/.gs/gems/minitest-5.9.0/lib/minitest/parallel.rb +0 -69
  62. data/.gs/gems/minitest-5.9.0/lib/minitest/pride.rb +0 -4
  63. data/.gs/gems/minitest-5.9.0/lib/minitest/pride_plugin.rb +0 -142
  64. data/.gs/gems/minitest-5.9.0/lib/minitest/spec.rb +0 -331
  65. data/.gs/gems/minitest-5.9.0/lib/minitest/test.rb +0 -284
  66. data/.gs/gems/minitest-5.9.0/lib/minitest/unit.rb +0 -45
  67. data/.gs/gems/minitest-5.9.0/lib/minitest.rb +0 -815
  68. data/.gs/gems/minitest-5.9.0/test/minitest/metametameta.rb +0 -90
  69. data/.gs/gems/minitest-5.9.0/test/minitest/test_minitest_benchmark.rb +0 -137
  70. data/.gs/gems/minitest-5.9.0/test/minitest/test_minitest_mock.rb +0 -512
  71. data/.gs/gems/minitest-5.9.0/test/minitest/test_minitest_reporter.rb +0 -281
  72. data/.gs/gems/minitest-5.9.0/test/minitest/test_minitest_spec.rb +0 -967
  73. data/.gs/gems/minitest-5.9.0/test/minitest/test_minitest_test.rb +0 -1983
  74. data/.gs/gems/multi_json-1.12.1/CHANGELOG.md +0 -245
  75. data/.gs/gems/multi_json-1.12.1/CONTRIBUTING.md +0 -46
  76. data/.gs/gems/multi_json-1.12.1/LICENSE.md +0 -20
  77. data/.gs/gems/multi_json-1.12.1/README.md +0 -121
  78. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapter.rb +0 -49
  79. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapter_error.rb +0 -15
  80. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/gson.rb +0 -20
  81. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/jr_jackson.rb +0 -25
  82. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/json_common.rb +0 -23
  83. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/json_gem.rb +0 -11
  84. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/json_pure.rb +0 -11
  85. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/nsjsonserialization.rb +0 -32
  86. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/oj.rb +0 -25
  87. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/ok_json.rb +0 -23
  88. data/.gs/gems/multi_json-1.12.1/lib/multi_json/adapters/yajl.rb +0 -19
  89. data/.gs/gems/multi_json-1.12.1/lib/multi_json/convertible_hash_keys.rb +0 -43
  90. data/.gs/gems/multi_json-1.12.1/lib/multi_json/options.rb +0 -39
  91. data/.gs/gems/multi_json-1.12.1/lib/multi_json/options_cache.rb +0 -29
  92. data/.gs/gems/multi_json-1.12.1/lib/multi_json/parse_error.rb +0 -17
  93. data/.gs/gems/multi_json-1.12.1/lib/multi_json/vendor/okjson.rb +0 -606
  94. data/.gs/gems/multi_json-1.12.1/lib/multi_json/version.rb +0 -17
  95. data/.gs/gems/multi_json-1.12.1/lib/multi_json.rb +0 -161
  96. data/.gs/gems/multi_json-1.12.1/multi_json.gemspec +0 -20
  97. data/.gs/gems/multipart-post-2.0.0/.gitignore +0 -6
  98. data/.gs/gems/multipart-post-2.0.0/.travis.yml +0 -7
  99. data/.gs/gems/multipart-post-2.0.0/Gemfile +0 -14
  100. data/.gs/gems/multipart-post-2.0.0/History.txt +0 -60
  101. data/.gs/gems/multipart-post-2.0.0/Manifest.txt +0 -9
  102. data/.gs/gems/multipart-post-2.0.0/README.md +0 -77
  103. data/.gs/gems/multipart-post-2.0.0/Rakefile +0 -9
  104. data/.gs/gems/multipart-post-2.0.0/lib/composite_io.rb +0 -108
  105. data/.gs/gems/multipart-post-2.0.0/lib/multipart_post.rb +0 -9
  106. data/.gs/gems/multipart-post-2.0.0/lib/multipartable.rb +0 -29
  107. data/.gs/gems/multipart-post-2.0.0/lib/net/http/post/multipart.rb +0 -27
  108. data/.gs/gems/multipart-post-2.0.0/lib/parts.rb +0 -96
  109. data/.gs/gems/multipart-post-2.0.0/multipart-post.gemspec +0 -22
  110. data/.gs/gems/multipart-post-2.0.0/test/multibyte.txt +0 -1
  111. data/.gs/gems/multipart-post-2.0.0/test/net/http/post/test_multipart.rb +0 -110
  112. data/.gs/gems/multipart-post-2.0.0/test/test_composite_io.rb +0 -115
  113. data/.gs/gems/multipart-post-2.0.0/test/test_parts.rb +0 -86
  114. data/.gs/specifications/faraday-0.9.2.gemspec +0 -31
  115. data/.gs/specifications/minitest-5.9.0.gemspec +0 -39
  116. data/.gs/specifications/multi_json-1.12.1.gemspec +0 -33
  117. data/.gs/specifications/multipart-post-2.0.0.gemspec +0 -22
  118. data/.ruby-version +0 -1
@@ -1,237 +0,0 @@
1
- module Faraday
2
- class Adapter
3
- # EventMachine adapter is useful for either asynchronous requests
4
- # when in EM reactor loop or for making parallel requests in
5
- # synchronous code.
6
- class EMHttp < Faraday::Adapter
7
- module Options
8
- def connection_config(env)
9
- options = {}
10
- configure_proxy(options, env)
11
- configure_timeout(options, env)
12
- configure_socket(options, env)
13
- configure_ssl(options, env)
14
- options
15
- end
16
-
17
- def request_config(env)
18
- options = {
19
- :body => read_body(env),
20
- :head => env[:request_headers],
21
- # :keepalive => true,
22
- # :file => 'path/to/file', # stream data off disk
23
- }
24
- configure_compression(options, env)
25
- options
26
- end
27
-
28
- def read_body(env)
29
- body = env[:body]
30
- body.respond_to?(:read) ? body.read : body
31
- end
32
-
33
- def configure_proxy(options, env)
34
- if proxy = request_options(env)[:proxy]
35
- options[:proxy] = {
36
- :host => proxy[:uri].host,
37
- :port => proxy[:uri].port,
38
- :authorization => [proxy[:user], proxy[:password]]
39
- }
40
- end
41
- end
42
-
43
- def configure_socket(options, env)
44
- if bind = request_options(env)[:bind]
45
- options[:bind] = {
46
- :host => bind[:host],
47
- :port => bind[:port]
48
- }
49
- end
50
- end
51
-
52
- def configure_ssl(options, env)
53
- if env[:url].scheme == 'https' && env[:ssl]
54
- options[:ssl] = {
55
- :cert_chain_file => env[:ssl][:ca_file],
56
- :verify_peer => env[:ssl].fetch(:verify, true)
57
- }
58
- end
59
- end
60
-
61
- def configure_timeout(options, env)
62
- timeout, open_timeout = request_options(env).values_at(:timeout, :open_timeout)
63
- options[:connect_timeout] = options[:inactivity_timeout] = timeout
64
- options[:connect_timeout] = open_timeout if open_timeout
65
- end
66
-
67
- def configure_compression(options, env)
68
- if env[:method] == :get and not options[:head].key? 'accept-encoding'
69
- options[:head]['accept-encoding'] = 'gzip, compressed'
70
- end
71
- end
72
-
73
- def request_options(env)
74
- env[:request]
75
- end
76
- end
77
-
78
- include Options
79
-
80
- dependency 'em-http'
81
-
82
- self.supports_parallel = true
83
-
84
- def self.setup_parallel_manager(options = nil)
85
- Manager.new
86
- end
87
-
88
- def call(env)
89
- super
90
- perform_request env
91
- @app.call env
92
- end
93
-
94
- def perform_request(env)
95
- if parallel?(env)
96
- manager = env[:parallel_manager]
97
- manager.add {
98
- perform_single_request(env).
99
- callback { env[:response].finish(env) }
100
- }
101
- else
102
- unless EventMachine.reactor_running?
103
- error = nil
104
- # start EM, block until request is completed
105
- EventMachine.run do
106
- perform_single_request(env).
107
- callback { EventMachine.stop }.
108
- errback { |client|
109
- error = error_message(client)
110
- EventMachine.stop
111
- }
112
- end
113
- raise_error(error) if error
114
- else
115
- # EM is running: instruct upstream that this is an async request
116
- env[:parallel_manager] = true
117
- perform_single_request(env).
118
- callback { env[:response].finish(env) }.
119
- errback {
120
- # TODO: no way to communicate the error in async mode
121
- raise NotImplementedError
122
- }
123
- end
124
- end
125
- rescue EventMachine::Connectify::CONNECTError => err
126
- if err.message.include?("Proxy Authentication Required")
127
- raise Error::ConnectionFailed, %{407 "Proxy Authentication Required "}
128
- else
129
- raise Error::ConnectionFailed, err
130
- end
131
- rescue => err
132
- if defined?(OpenSSL) && OpenSSL::SSL::SSLError === err
133
- raise Faraday::SSLError, err
134
- else
135
- raise
136
- end
137
- end
138
-
139
- # TODO: reuse the connection to support pipelining
140
- def perform_single_request(env)
141
- req = EventMachine::HttpRequest.new(env[:url], connection_config(env))
142
- req.setup_request(env[:method], request_config(env)).callback { |client|
143
- save_response(env, client.response_header.status, client.response) do |resp_headers|
144
- client.response_header.each do |name, value|
145
- resp_headers[name.to_sym] = value
146
- end
147
- end
148
- }
149
- end
150
-
151
- def error_message(client)
152
- client.error or "request failed"
153
- end
154
-
155
- def raise_error(msg)
156
- errklass = Faraday::Error::ClientError
157
- if msg == Errno::ETIMEDOUT
158
- errklass = Faraday::Error::TimeoutError
159
- msg = "request timed out"
160
- elsif msg == Errno::ECONNREFUSED
161
- errklass = Faraday::Error::ConnectionFailed
162
- msg = "connection refused"
163
- elsif msg == "connection closed by server"
164
- errklass = Faraday::Error::ConnectionFailed
165
- end
166
- raise errklass, msg
167
- end
168
-
169
- def parallel?(env)
170
- !!env[:parallel_manager]
171
- end
172
-
173
- # The parallel manager is designed to start an EventMachine loop
174
- # and block until all registered requests have been completed.
175
- class Manager
176
- def initialize
177
- reset
178
- end
179
-
180
- def reset
181
- @registered_procs = []
182
- @num_registered = 0
183
- @num_succeeded = 0
184
- @errors = []
185
- @running = false
186
- end
187
-
188
- def running?() @running end
189
-
190
- def add
191
- if running?
192
- perform_request { yield }
193
- else
194
- @registered_procs << Proc.new
195
- end
196
- @num_registered += 1
197
- end
198
-
199
- def run
200
- if @num_registered > 0
201
- @running = true
202
- EventMachine.run do
203
- @registered_procs.each do |proc|
204
- perform_request(&proc)
205
- end
206
- end
207
- if @errors.size > 0
208
- raise Faraday::Error::ClientError, @errors.first || "connection failed"
209
- end
210
- end
211
- ensure
212
- reset
213
- end
214
-
215
- def perform_request
216
- client = yield
217
- client.callback { @num_succeeded += 1; check_finished }
218
- client.errback { @errors << client.error; check_finished }
219
- end
220
-
221
- def check_finished
222
- if @num_succeeded + @errors.size == @num_registered
223
- EventMachine.stop
224
- end
225
- end
226
- end
227
- end
228
- end
229
- end
230
-
231
- begin
232
- require 'openssl'
233
- rescue LoadError
234
- warn "Warning: no such file to load -- openssl. Make sure it is installed if you want HTTPS support"
235
- else
236
- require 'faraday/adapter/em_http_ssl_patch'
237
- end if Faraday::Adapter::EMHttp.loaded?
@@ -1,56 +0,0 @@
1
- require 'openssl'
2
- require 'em-http'
3
-
4
- module EmHttpSslPatch
5
- def ssl_verify_peer(cert_string)
6
- cert = nil
7
- begin
8
- cert = OpenSSL::X509::Certificate.new(cert_string)
9
- rescue OpenSSL::X509::CertificateError
10
- return false
11
- end
12
-
13
- @last_seen_cert = cert
14
-
15
- if certificate_store.verify(@last_seen_cert)
16
- begin
17
- certificate_store.add_cert(@last_seen_cert)
18
- rescue OpenSSL::X509::StoreError => e
19
- raise e unless e.message == 'cert already in hash table'
20
- end
21
- true
22
- else
23
- raise OpenSSL::SSL::SSLError.new(%(unable to verify the server certificate for "#{host}"))
24
- end
25
- end
26
-
27
- def ssl_handshake_completed
28
- return true unless verify_peer?
29
-
30
- unless OpenSSL::SSL.verify_certificate_identity(@last_seen_cert, host)
31
- raise OpenSSL::SSL::SSLError.new(%(host "#{host}" does not match the server certificate))
32
- else
33
- true
34
- end
35
- end
36
-
37
- def verify_peer?
38
- parent.connopts.tls[:verify_peer]
39
- end
40
-
41
- def host
42
- parent.connopts.host
43
- end
44
-
45
- def certificate_store
46
- @certificate_store ||= begin
47
- store = OpenSSL::X509::Store.new
48
- store.set_default_paths
49
- ca_file = parent.connopts.tls[:cert_chain_file]
50
- store.add_file(ca_file) if ca_file
51
- store
52
- end
53
- end
54
- end
55
-
56
- EventMachine::HttpStubConnection.send(:include, EmHttpSslPatch)
@@ -1,66 +0,0 @@
1
- module Faraday
2
- class Adapter
3
- class EMSynchrony < Faraday::Adapter
4
- class ParallelManager
5
-
6
- # Add requests to queue. The `request` argument should be a
7
- # `EM::HttpRequest` object.
8
- def add(request, method, *args, &block)
9
- queue << {
10
- :request => request,
11
- :method => method,
12
- :args => args,
13
- :block => block
14
- }
15
- end
16
-
17
- # Run all requests on queue with `EM::Synchrony::Multi`, wrapping
18
- # it in a reactor and fiber if needed.
19
- def run
20
- result = nil
21
- if !EM.reactor_running?
22
- EM.run {
23
- Fiber.new do
24
- result = perform
25
- EM.stop
26
- end.resume
27
- }
28
- else
29
- result = perform
30
- end
31
- result
32
- end
33
-
34
-
35
- private
36
-
37
- # The request queue.
38
- def queue
39
- @queue ||= []
40
- end
41
-
42
- # Main `EM::Synchrony::Multi` performer.
43
- def perform
44
- multi = ::EM::Synchrony::Multi.new
45
-
46
- queue.each do |item|
47
- method = "a#{item[:method]}".to_sym
48
-
49
- req = item[:request].send(method, *item[:args])
50
- req.callback(&item[:block])
51
-
52
- req_name = "req_#{multi.requests.size}".to_sym
53
- multi.add(req_name, req)
54
- end
55
-
56
- # Clear the queue, so parallel manager objects can be reused.
57
- @queue = []
58
-
59
- # Block fiber until all requests have returned.
60
- multi.perform
61
- end
62
-
63
- end # ParallelManager
64
- end # EMSynchrony
65
- end # Adapter
66
- end # Faraday
@@ -1,100 +0,0 @@
1
- require 'uri'
2
-
3
- module Faraday
4
- class Adapter
5
- class EMSynchrony < Faraday::Adapter
6
- include EMHttp::Options
7
-
8
- dependency do
9
- require 'em-synchrony/em-http'
10
- require 'em-synchrony/em-multi'
11
- require 'fiber'
12
- end
13
-
14
- self.supports_parallel = true
15
-
16
- def self.setup_parallel_manager(options = {})
17
- ParallelManager.new
18
- end
19
-
20
- def call(env)
21
- super
22
- request = EventMachine::HttpRequest.new(Utils::URI(env[:url].to_s), connection_config(env))
23
-
24
- http_method = env[:method].to_s.downcase.to_sym
25
-
26
- # Queue requests for parallel execution.
27
- if env[:parallel_manager]
28
- env[:parallel_manager].add(request, http_method, request_config(env)) do |resp|
29
- save_response(env, resp.response_header.status, resp.response) do |resp_headers|
30
- resp.response_header.each do |name, value|
31
- resp_headers[name.to_sym] = value
32
- end
33
- end
34
-
35
- # Finalize the response object with values from `env`.
36
- env[:response].finish(env)
37
- end
38
-
39
- # Execute single request.
40
- else
41
- client = nil
42
- block = lambda { request.send(http_method, request_config(env)) }
43
-
44
- if !EM.reactor_running?
45
- EM.run do
46
- Fiber.new {
47
- client = block.call
48
- EM.stop
49
- }.resume
50
- end
51
- else
52
- client = block.call
53
- end
54
-
55
- raise client.error if client.error
56
-
57
- save_response(env, client.response_header.status, client.response) do |resp_headers|
58
- client.response_header.each do |name, value|
59
- resp_headers[name.to_sym] = value
60
- end
61
- end
62
- end
63
-
64
- @app.call env
65
- rescue Errno::ECONNREFUSED
66
- raise Error::ConnectionFailed, $!
67
- rescue EventMachine::Connectify::CONNECTError => err
68
- if err.message.include?("Proxy Authentication Required")
69
- raise Error::ConnectionFailed, %{407 "Proxy Authentication Required "}
70
- else
71
- raise Error::ConnectionFailed, err
72
- end
73
- rescue Errno::ETIMEDOUT => err
74
- raise Error::TimeoutError, err
75
- rescue RuntimeError => err
76
- if err.message == "connection closed by server"
77
- raise Error::ConnectionFailed, err
78
- else
79
- raise
80
- end
81
- rescue => err
82
- if defined?(OpenSSL) && OpenSSL::SSL::SSLError === err
83
- raise Faraday::SSLError, err
84
- else
85
- raise
86
- end
87
- end
88
- end
89
- end
90
- end
91
-
92
- require 'faraday/adapter/em_synchrony/parallel_manager'
93
-
94
- begin
95
- require 'openssl'
96
- rescue LoadError
97
- warn "Warning: no such file to load -- openssl. Make sure it is installed if you want HTTPS support"
98
- else
99
- require 'faraday/adapter/em_http_ssl_patch'
100
- end if Faraday::Adapter::EMSynchrony.loaded?
@@ -1,81 +0,0 @@
1
- module Faraday
2
- class Adapter
3
- class Excon < Faraday::Adapter
4
- dependency 'excon'
5
-
6
- def initialize(app, connection_options = {})
7
- @connection_options = connection_options
8
- super(app)
9
- end
10
-
11
- def call(env)
12
- super
13
-
14
- opts = {}
15
- if env[:url].scheme == 'https' && ssl = env[:ssl]
16
- opts[:ssl_verify_peer] = !!ssl.fetch(:verify, true)
17
- opts[:ssl_ca_path] = ssl[:ca_path] if ssl[:ca_path]
18
- opts[:ssl_ca_file] = ssl[:ca_file] if ssl[:ca_file]
19
- opts[:client_cert] = ssl[:client_cert] if ssl[:client_cert]
20
- opts[:client_key] = ssl[:client_key] if ssl[:client_key]
21
- opts[:certificate] = ssl[:certificate] if ssl[:certificate]
22
- opts[:private_key] = ssl[:private_key] if ssl[:private_key]
23
-
24
- # https://github.com/geemus/excon/issues/106
25
- # https://github.com/jruby/jruby-ossl/issues/19
26
- opts[:nonblock] = false
27
- end
28
-
29
- if ( req = env[:request] )
30
- if req[:timeout]
31
- opts[:read_timeout] = req[:timeout]
32
- opts[:connect_timeout] = req[:timeout]
33
- opts[:write_timeout] = req[:timeout]
34
- end
35
-
36
- if req[:open_timeout]
37
- opts[:connect_timeout] = req[:open_timeout]
38
- opts[:write_timeout] = req[:open_timeout]
39
- end
40
-
41
- if req[:proxy]
42
- opts[:proxy] = {
43
- :host => req[:proxy][:uri].host,
44
- :hostname => req[:proxy][:uri].hostname,
45
- :port => req[:proxy][:uri].port,
46
- :scheme => req[:proxy][:uri].scheme,
47
- :user => req[:proxy][:user],
48
- :password => req[:proxy][:password]
49
- }
50
- end
51
- end
52
-
53
- conn = ::Excon.new(env[:url].to_s, opts.merge(@connection_options))
54
-
55
- resp = conn.request \
56
- :method => env[:method].to_s.upcase,
57
- :headers => env[:request_headers],
58
- :body => read_body(env)
59
-
60
- save_response(env, resp.status.to_i, resp.body, resp.headers)
61
-
62
- @app.call env
63
- rescue ::Excon::Errors::SocketError => err
64
- if err.message =~ /\btimeout\b/
65
- raise Error::TimeoutError, err
66
- elsif err.message =~ /\bcertificate\b/
67
- raise Faraday::SSLError, err
68
- else
69
- raise Error::ConnectionFailed, err
70
- end
71
- rescue ::Excon::Errors::Timeout => err
72
- raise Error::TimeoutError, err
73
- end
74
-
75
- # TODO: support streaming requests
76
- def read_body(env)
77
- env[:body].respond_to?(:read) ? env[:body].read : env[:body]
78
- end
79
- end
80
- end
81
- end
@@ -1,117 +0,0 @@
1
- module Faraday
2
- class Adapter
3
- class HTTPClient < Faraday::Adapter
4
- dependency 'httpclient'
5
-
6
- def client
7
- @client ||= ::HTTPClient.new
8
- end
9
-
10
- def call(env)
11
- super
12
-
13
- # enable compression
14
- client.transparent_gzip_decompression = true
15
-
16
- if req = env[:request]
17
- if proxy = req[:proxy]
18
- configure_proxy proxy
19
- end
20
-
21
- if bind = req[:bind]
22
- configure_socket bind
23
- end
24
-
25
- configure_timeouts req
26
- end
27
-
28
- if env[:url].scheme == 'https' && ssl = env[:ssl]
29
- configure_ssl ssl
30
- end
31
-
32
- # TODO Don't stream yet.
33
- # https://github.com/nahi/httpclient/pull/90
34
- env[:body] = env[:body].read if env[:body].respond_to? :read
35
-
36
- resp = client.request env[:method], env[:url],
37
- :body => env[:body],
38
- :header => env[:request_headers]
39
-
40
- save_response env, resp.status, resp.body, resp.headers
41
-
42
- @app.call env
43
- rescue ::HTTPClient::TimeoutError, Errno::ETIMEDOUT
44
- raise Faraday::Error::TimeoutError, $!
45
- rescue ::HTTPClient::BadResponseError => err
46
- if err.message.include?('status 407')
47
- raise Faraday::Error::ConnectionFailed, %{407 "Proxy Authentication Required "}
48
- else
49
- raise Faraday::Error::ClientError, $!
50
- end
51
- rescue Errno::ECONNREFUSED, EOFError
52
- raise Faraday::Error::ConnectionFailed, $!
53
- rescue => err
54
- if defined?(OpenSSL) && OpenSSL::SSL::SSLError === err
55
- raise Faraday::SSLError, err
56
- else
57
- raise
58
- end
59
- end
60
-
61
- def configure_socket(bind)
62
- client.socket_local.host = bind[:host]
63
- client.socket_local.port = bind[:port]
64
- end
65
-
66
- def configure_proxy(proxy)
67
- client.proxy = proxy[:uri]
68
- if proxy[:user] && proxy[:password]
69
- client.set_proxy_auth proxy[:user], proxy[:password]
70
- end
71
- end
72
-
73
- def configure_ssl(ssl)
74
- ssl_config = client.ssl_config
75
- ssl_config.verify_mode = ssl_verify_mode(ssl)
76
- ssl_config.cert_store = ssl_cert_store(ssl)
77
-
78
- ssl_config.add_trust_ca ssl[:ca_file] if ssl[:ca_file]
79
- ssl_config.add_trust_ca ssl[:ca_path] if ssl[:ca_path]
80
- ssl_config.client_cert = ssl[:client_cert] if ssl[:client_cert]
81
- ssl_config.client_key = ssl[:client_key] if ssl[:client_key]
82
- ssl_config.verify_depth = ssl[:verify_depth] if ssl[:verify_depth]
83
- end
84
-
85
- def configure_timeouts(req)
86
- if req[:timeout]
87
- client.connect_timeout = req[:timeout]
88
- client.receive_timeout = req[:timeout]
89
- client.send_timeout = req[:timeout]
90
- end
91
-
92
- if req[:open_timeout]
93
- client.connect_timeout = req[:open_timeout]
94
- client.send_timeout = req[:open_timeout]
95
- end
96
- end
97
-
98
- def ssl_cert_store(ssl)
99
- return ssl[:cert_store] if ssl[:cert_store]
100
- # Use the default cert store by default, i.e. system ca certs
101
- cert_store = OpenSSL::X509::Store.new
102
- cert_store.set_default_paths
103
- cert_store
104
- end
105
-
106
- def ssl_verify_mode(ssl)
107
- ssl[:verify_mode] || begin
108
- if ssl.fetch(:verify, true)
109
- OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT
110
- else
111
- OpenSSL::SSL::VERIFY_NONE
112
- end
113
- end
114
- end
115
- end
116
- end
117
- end