faraday 0.11.0 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +380 -0
- data/LICENSE.md +1 -1
- data/README.md +25 -229
- data/Rakefile +7 -0
- data/examples/client_spec.rb +65 -0
- data/examples/client_test.rb +79 -0
- data/lib/faraday/adapter/httpclient.rb +83 -59
- data/lib/faraday/adapter/patron.rb +92 -36
- data/lib/faraday/adapter/rack.rb +30 -13
- data/lib/faraday/adapter/test.rb +103 -62
- data/lib/faraday/adapter/typhoeus.rb +7 -115
- data/lib/faraday/adapter.rb +77 -22
- data/lib/faraday/adapter_registry.rb +30 -0
- data/lib/faraday/autoload.rb +42 -36
- data/lib/faraday/connection.rb +351 -167
- data/lib/faraday/dependency_loader.rb +37 -0
- data/lib/faraday/encoders/flat_params_encoder.rb +105 -0
- data/lib/faraday/encoders/nested_params_encoder.rb +176 -0
- data/lib/faraday/error.rb +127 -38
- data/lib/faraday/file_part.rb +128 -0
- data/lib/faraday/logging/formatter.rb +105 -0
- data/lib/faraday/methods.rb +6 -0
- data/lib/faraday/middleware.rb +19 -25
- data/lib/faraday/middleware_registry.rb +129 -0
- data/lib/faraday/options/connection_options.rb +22 -0
- data/lib/faraday/options/env.rb +181 -0
- data/lib/faraday/options/proxy_options.rb +32 -0
- data/lib/faraday/options/request_options.rb +22 -0
- data/lib/faraday/options/ssl_options.rb +59 -0
- data/lib/faraday/options.rb +58 -207
- data/lib/faraday/param_part.rb +53 -0
- data/lib/faraday/parameters.rb +4 -196
- data/lib/faraday/rack_builder.rb +84 -48
- data/lib/faraday/request/authorization.rb +44 -30
- data/lib/faraday/request/basic_authentication.rb +14 -7
- data/lib/faraday/request/instrumentation.rb +45 -27
- data/lib/faraday/request/multipart.rb +88 -45
- data/lib/faraday/request/retry.rb +211 -126
- data/lib/faraday/request/token_authentication.rb +15 -10
- data/lib/faraday/request/url_encoded.rb +43 -23
- data/lib/faraday/request.rb +94 -32
- data/lib/faraday/response/logger.rb +22 -69
- data/lib/faraday/response/raise_error.rb +49 -14
- data/lib/faraday/response.rb +27 -23
- data/lib/faraday/utils/headers.rb +139 -0
- data/lib/faraday/utils/params_hash.rb +61 -0
- data/lib/faraday/utils.rb +38 -238
- data/lib/faraday/version.rb +5 -0
- data/lib/faraday.rb +124 -187
- data/spec/external_adapters/faraday_specs_setup.rb +14 -0
- data/spec/faraday/adapter/em_http_spec.rb +47 -0
- data/spec/faraday/adapter/em_synchrony_spec.rb +16 -0
- data/spec/faraday/adapter/excon_spec.rb +49 -0
- data/spec/faraday/adapter/httpclient_spec.rb +73 -0
- data/spec/faraday/adapter/net_http_spec.rb +64 -0
- data/spec/faraday/adapter/patron_spec.rb +18 -0
- data/spec/faraday/adapter/rack_spec.rb +8 -0
- data/spec/faraday/adapter/test_spec.rb +260 -0
- data/spec/faraday/adapter/typhoeus_spec.rb +7 -0
- data/spec/faraday/adapter_registry_spec.rb +28 -0
- data/spec/faraday/adapter_spec.rb +55 -0
- data/spec/faraday/composite_read_io_spec.rb +80 -0
- data/spec/faraday/connection_spec.rb +736 -0
- data/spec/faraday/error_spec.rb +60 -0
- data/spec/faraday/middleware_spec.rb +52 -0
- data/spec/faraday/options/env_spec.rb +70 -0
- data/spec/faraday/options/options_spec.rb +297 -0
- data/spec/faraday/options/proxy_options_spec.rb +44 -0
- data/spec/faraday/options/request_options_spec.rb +19 -0
- data/spec/faraday/params_encoders/flat_spec.rb +42 -0
- data/spec/faraday/params_encoders/nested_spec.rb +142 -0
- data/spec/faraday/rack_builder_spec.rb +345 -0
- data/spec/faraday/request/authorization_spec.rb +88 -0
- data/spec/faraday/request/instrumentation_spec.rb +76 -0
- data/spec/faraday/request/multipart_spec.rb +302 -0
- data/spec/faraday/request/retry_spec.rb +242 -0
- data/spec/faraday/request/url_encoded_spec.rb +83 -0
- data/spec/faraday/request_spec.rb +120 -0
- data/spec/faraday/response/logger_spec.rb +220 -0
- data/spec/faraday/response/middleware_spec.rb +68 -0
- data/spec/faraday/response/raise_error_spec.rb +169 -0
- data/spec/faraday/response_spec.rb +75 -0
- data/spec/faraday/utils/headers_spec.rb +82 -0
- data/spec/faraday/utils_spec.rb +56 -0
- data/spec/faraday_spec.rb +37 -0
- data/spec/spec_helper.rb +132 -0
- data/spec/support/disabling_stub.rb +14 -0
- data/spec/support/fake_safe_buffer.rb +15 -0
- data/spec/support/helper_methods.rb +133 -0
- data/spec/support/shared_examples/adapter.rb +105 -0
- data/spec/support/shared_examples/params_encoder.rb +18 -0
- data/spec/support/shared_examples/request_method.rb +262 -0
- data/spec/support/streaming_response_checker.rb +35 -0
- data/spec/support/webmock_rack_app.rb +68 -0
- metadata +164 -16
- data/lib/faraday/adapter/em_http.rb +0 -243
- data/lib/faraday/adapter/em_http_ssl_patch.rb +0 -56
- data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +0 -66
- data/lib/faraday/adapter/em_synchrony.rb +0 -106
- data/lib/faraday/adapter/excon.rb +0 -80
- data/lib/faraday/adapter/net_http.rb +0 -135
- data/lib/faraday/adapter/net_http_persistent.rb +0 -50
- data/lib/faraday/upload_io.rb +0 -67
@@ -1,50 +0,0 @@
|
|
1
|
-
# Rely on autoloading instead of explicit require; helps avoid the "already
|
2
|
-
# initialized constant" warning on Ruby 1.8.7 when NetHttp is refereced below.
|
3
|
-
# require 'faraday/adapter/net_http'
|
4
|
-
|
5
|
-
module Faraday
|
6
|
-
class Adapter
|
7
|
-
class NetHttpPersistent < NetHttp
|
8
|
-
dependency 'net/http/persistent'
|
9
|
-
|
10
|
-
def net_http_connection(env)
|
11
|
-
if (proxy = env[:request][:proxy])
|
12
|
-
proxy_uri = ::URI::HTTP === proxy[:uri] ? proxy[:uri].dup : ::URI.parse(proxy[:uri].to_s)
|
13
|
-
proxy_uri.user = proxy_uri.password = nil
|
14
|
-
# awful patch for net-http-persistent 2.8 not unescaping user/password
|
15
|
-
(class << proxy_uri; self; end).class_eval do
|
16
|
-
define_method(:user) { proxy[:user] }
|
17
|
-
define_method(:password) { proxy[:password] }
|
18
|
-
end if proxy[:user]
|
19
|
-
return Net::HTTP::Persistent.new 'Faraday', proxy_uri
|
20
|
-
end
|
21
|
-
|
22
|
-
Net::HTTP::Persistent.new 'Faraday'
|
23
|
-
end
|
24
|
-
|
25
|
-
def perform_request(http, env)
|
26
|
-
http.request env[:url], create_request(env)
|
27
|
-
rescue Errno::ETIMEDOUT => error
|
28
|
-
raise Faraday::Error::TimeoutError, error
|
29
|
-
rescue Net::HTTP::Persistent::Error => error
|
30
|
-
if error.message.include? 'Timeout'
|
31
|
-
raise Faraday::Error::TimeoutError, error
|
32
|
-
elsif error.message.include? 'connection refused'
|
33
|
-
raise Faraday::Error::ConnectionFailed, error
|
34
|
-
else
|
35
|
-
raise
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def configure_ssl(http, ssl)
|
40
|
-
http.verify_mode = ssl_verify_mode(ssl)
|
41
|
-
http.cert_store = ssl_cert_store(ssl)
|
42
|
-
|
43
|
-
http.certificate = ssl[:client_cert] if ssl[:client_cert]
|
44
|
-
http.private_key = ssl[:client_key] if ssl[:client_key]
|
45
|
-
http.ca_file = ssl[:ca_file] if ssl[:ca_file]
|
46
|
-
http.ssl_version = ssl[:version] if ssl[:version]
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
data/lib/faraday/upload_io.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'composite_io'
|
3
|
-
require 'parts'
|
4
|
-
require 'stringio'
|
5
|
-
rescue LoadError
|
6
|
-
$stderr.puts "Install the multipart-post gem."
|
7
|
-
raise
|
8
|
-
end
|
9
|
-
|
10
|
-
module Faraday
|
11
|
-
# Similar but not compatible with ::CompositeReadIO provided by multipart-post.
|
12
|
-
class CompositeReadIO
|
13
|
-
def initialize(*parts)
|
14
|
-
@parts = parts.flatten
|
15
|
-
@ios = @parts.map { |part| part.to_io }
|
16
|
-
@index = 0
|
17
|
-
end
|
18
|
-
|
19
|
-
def length
|
20
|
-
@parts.inject(0) { |sum, part| sum + part.length }
|
21
|
-
end
|
22
|
-
|
23
|
-
def rewind
|
24
|
-
@ios.each { |io| io.rewind }
|
25
|
-
@index = 0
|
26
|
-
end
|
27
|
-
|
28
|
-
# Read from IOs in order until `length` bytes have been received.
|
29
|
-
def read(length = nil, outbuf = nil)
|
30
|
-
got_result = false
|
31
|
-
outbuf = outbuf ? outbuf.replace("") : ""
|
32
|
-
|
33
|
-
while io = current_io
|
34
|
-
if result = io.read(length)
|
35
|
-
got_result ||= !result.nil?
|
36
|
-
result.force_encoding("BINARY") if result.respond_to?(:force_encoding)
|
37
|
-
outbuf << result
|
38
|
-
length -= result.length if length
|
39
|
-
break if length == 0
|
40
|
-
end
|
41
|
-
advance_io
|
42
|
-
end
|
43
|
-
(!got_result && length) ? nil : outbuf
|
44
|
-
end
|
45
|
-
|
46
|
-
def close
|
47
|
-
@ios.each { |io| io.close }
|
48
|
-
end
|
49
|
-
|
50
|
-
def ensure_open_and_readable
|
51
|
-
# Rubinius compatibility
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
def current_io
|
57
|
-
@ios[@index]
|
58
|
-
end
|
59
|
-
|
60
|
-
def advance_io
|
61
|
-
@index += 1
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
UploadIO = ::UploadIO
|
66
|
-
Parts = ::Parts
|
67
|
-
end
|