faraday 1.0.0 → 1.0.1

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: 9d3d650c5d465a0862cddd7ab2ed27fbfb4a6e5f2cfcbb54ba753bcc1ce9e40e
4
- data.tar.gz: 953336deeb3dd2e0228368209bdffc7815b376772269c439e21374bc22b70484
3
+ metadata.gz: 1d23ec0aefc40d23ccc4410db08092bd29e477309fb8aa6794b3c8401961de10
4
+ data.tar.gz: c33ca7313dcccbf148266a80aa4e12d4cba96a4feb96ecfc3e8ff50fa06756c5
5
5
  SHA512:
6
- metadata.gz: b80c084a8714d995dec61c918891a63720dbcdddf2eb3ecb7106f40a03bb341c4f03ffe976365c5450b2dcffd0b1f52c1cd4320ea24591dfaef7d5fdbbe12562
7
- data.tar.gz: 67f8134fae885d3bb2e621afa701d6d535409bbb0141ad699f4d290059d61bf856915f622e214251f05e8b893a69bf68439118074712a22e75e3705b249dbb85
6
+ metadata.gz: 8058c22dc6e78bc3d46a9c8a22c458656a1380a4aed62b31e11b9b054fc6791373dd103276fc018148daed3934a724bcb39390bbe88e2762281ff810b61b408d
7
+ data.tar.gz: 341f3b44148f666bb03f8e7b232fd92e26b8c34d758090e6e82f1276af29ff17d4f62bdb58871254ba48b2232ab58269c71db08df7a4b0c35c53f2c7e9bbe7e8
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ![Faraday](./docs/assets/img/repo-card-slim.png)
1
+ # [![Faraday](./docs/assets/img/repo-card-slim.png)][website]
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/faraday.svg)](https://rubygems.org/gems/faraday)
4
4
  ![GitHub Actions CI](https://github.com/lostisland/faraday/workflows/CI/badge.svg)
@@ -19,7 +19,7 @@ require 'faraday/dependency_loader'
19
19
  # conn.get '/'
20
20
  #
21
21
  module Faraday
22
- VERSION = '1.0.0'
22
+ VERSION = '1.0.1'
23
23
  METHODS_WITH_QUERY = %w[get head delete trace].freeze
24
24
  METHODS_WITH_BODY = %w[post put patch].freeze
25
25
 
@@ -153,7 +153,7 @@ module Faraday
153
153
  @default_connection_options = ConnectionOptions.from(options)
154
154
  end
155
155
 
156
- unless const_defined? :Timer
156
+ unless defined?(::Faraday::Timer)
157
157
  require 'timeout'
158
158
  Timer = Timeout
159
159
  end
@@ -142,7 +142,8 @@ module Faraday
142
142
 
143
143
  raise Faraday::ConnectionFailed, e
144
144
  rescue StandardError => e
145
- if defined?(OpenSSL) && e.is_a?(OpenSSL::SSL::SSLError)
145
+ if defined?(::OpenSSL::SSL::SSLError) && \
146
+ e.is_a?(::OpenSSL::SSL::SSLError)
146
147
  raise Faraday::SSLError, e
147
148
  end
148
149
 
@@ -66,7 +66,8 @@ module Faraday
66
66
  rescue Errno::EADDRNOTAVAIL, Errno::ECONNREFUSED, IOError, SocketError
67
67
  raise Faraday::ConnectionFailed, $ERROR_INFO
68
68
  rescue StandardError => e
69
- if defined?(OpenSSL) && e.is_a?(OpenSSL::SSL::SSLError)
69
+ if defined?(::OpenSSL::SSL::SSLError) && \
70
+ e.is_a?(::OpenSSL::SSL::SSLError)
70
71
  raise Faraday::SSLError, e
71
72
  end
72
73
 
@@ -30,8 +30,10 @@ module Faraday
30
30
  Zlib::GzipFile::Error
31
31
  ]
32
32
 
33
- exceptions << OpenSSL::SSL::SSLError if defined?(OpenSSL)
34
- exceptions << Net::OpenTimeout if defined?(Net::OpenTimeout)
33
+ if defined?(::OpenSSL::SSL::SSLError)
34
+ exceptions << ::OpenSSL::SSL::SSLError
35
+ end
36
+ exceptions << ::Net::OpenTimeout if defined?(::Net::OpenTimeout)
35
37
 
36
38
  NET_HTTP_EXCEPTIONS = exceptions.freeze
37
39
 
@@ -137,16 +139,24 @@ module Faraday
137
139
  end
138
140
 
139
141
  def request_via_get_method(http, env, &block)
140
- http.get env[:url].request_uri, env[:request_headers], &block
142
+ # Must use Net::HTTP#start and pass it a block otherwise the server's
143
+ # TCP socket does not close correctly.
144
+ http.start do |opened_http|
145
+ opened_http.get env[:url].request_uri, env[:request_headers], &block
146
+ end
141
147
  end
142
148
 
143
149
  def request_via_request_method(http, env, &block)
144
- if block_given?
145
- http.request create_request(env) do |response|
146
- response.read_body(&block)
150
+ # Must use Net::HTTP#start and pass it a block otherwise the server's
151
+ # TCP socket does not close correctly.
152
+ http.start do |opened_http|
153
+ if block_given?
154
+ opened_http.request create_request(env) do |response|
155
+ response.read_body(&block)
156
+ end
157
+ else
158
+ opened_http.request create_request(env)
147
159
  end
148
- else
149
- http.request create_request(env)
150
160
  end
151
161
  end
152
162
 
@@ -3,7 +3,7 @@
3
3
  module Faraday
4
4
  class Adapter
5
5
  # Typhoeus adapter. This class is just a stub, the real adapter is in
6
- # https://github.com/philsturgeon/typhoeus/blob/master/lib/typhoeus/adapters/faraday.rb
6
+ # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/adapters/faraday.rb
7
7
  class Typhoeus < Faraday::Adapter
8
8
  # Needs to define this method in order to support Typhoeus <= 1.3.0
9
9
  def call; end
@@ -12,7 +12,9 @@ module Faraday
12
12
  end
13
13
 
14
14
  def get(name)
15
- klass = @constants[name]
15
+ klass = @lock.synchronize do
16
+ @constants[name]
17
+ end
16
18
  return klass if klass
17
19
 
18
20
  Object.const_get(name).tap { |c| set(c, name) }
@@ -4,7 +4,9 @@ module Faraday
4
4
  class Request
5
5
  # Request middleware for the Authorization HTTP header
6
6
  class Authorization < Faraday::Middleware
7
- KEY = 'Authorization' unless defined? KEY
7
+ unless defined?(::Faraday::Request::Authorization::KEY)
8
+ KEY = 'Authorization'
9
+ end
8
10
 
9
11
  # @param type [String, Symbol]
10
12
  # @param token [String, Symbol, Hash]
@@ -8,7 +8,7 @@ module Faraday
8
8
  # Middleware for supporting multi-part requests.
9
9
  class Multipart < UrlEncoded
10
10
  self.mime_type = 'multipart/form-data'
11
- unless defined? DEFAULT_BOUNDARY_PREFIX
11
+ unless defined?(::Faraday::Request::Multipart::DEFAULT_BOUNDARY_PREFIX)
12
12
  DEFAULT_BOUNDARY_PREFIX = '-----------RubyMultipartPost'
13
13
  end
14
14
 
@@ -4,7 +4,9 @@ module Faraday
4
4
  class Request
5
5
  # Middleware for supporting urlencoded requests.
6
6
  class UrlEncoded < Faraday::Middleware
7
- CONTENT_TYPE = 'Content-Type' unless defined? CONTENT_TYPE
7
+ unless defined?(::Faraday::Request::UrlEncoded::CONTENT_TYPE)
8
+ CONTENT_TYPE = 'Content-Type'
9
+ end
8
10
 
9
11
  class << self
10
12
  attr_accessor :mime_type
@@ -15,8 +15,11 @@ module Faraday
15
15
 
16
16
  # Override this to modify the environment after the response has finished.
17
17
  # Calls the `parse` method if defined
18
+ # `parse` method can be defined as private, public and protected
18
19
  def on_complete(env)
19
- env.body = parse(env.body) if respond_to?(:parse) && env.parse_body?
20
+ return unless respond_to?(:parse, true) && env.parse_body?
21
+
22
+ env.body = parse(env.body)
20
23
  end
21
24
  end
22
25
 
@@ -16,12 +16,20 @@ module Faraday
16
16
  NestedParamsEncoder.encode(params)
17
17
  end
18
18
 
19
+ def default_space_encoding
20
+ @default_space_encoding ||= '+'
21
+ end
22
+
23
+ class << self
24
+ attr_writer :default_space_encoding
25
+ end
26
+
19
27
  ESCAPE_RE = /[^a-zA-Z0-9 .~_-]/.freeze
20
28
 
21
29
  def escape(str)
22
30
  str.to_s.gsub(ESCAPE_RE) do |match|
23
31
  '%' + match.unpack('H2' * match.bytesize).join('%').upcase
24
- end.tr(' ', '+')
32
+ end.gsub(' ', default_space_encoding)
25
33
  end
26
34
 
27
35
  def unescape(str)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe Faraday::Adapter::EMHttp do
3
+ RSpec.describe Faraday::Adapter::EMHttp, unless: defined?(JRUBY_VERSION) do
4
4
  features :request_body_on_query_methods, :reason_phrase_parse, :trace_method,
5
5
  :skip_response_body_on_head, :parallel, :local_socket_binding
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe Faraday::Adapter::EMSynchrony do
3
+ RSpec.describe Faraday::Adapter::EMSynchrony, unless: defined?(JRUBY_VERSION) do
4
4
  features :request_body_on_query_methods, :reason_phrase_parse,
5
5
  :skip_response_body_on_head, :parallel, :local_socket_binding
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe Faraday::Adapter::Patron do
3
+ RSpec.describe Faraday::Adapter::Patron, unless: defined?(JRUBY_VERSION) do
4
4
  features :reason_phrase_parse
5
5
 
6
6
  it_behaves_like 'an adapter'
@@ -189,7 +189,7 @@ RSpec.describe Faraday::RackBuilder do
189
189
 
190
190
  it 'raises an error while making a request' do
191
191
  expect { conn.get('/') }.to raise_error(RuntimeError) do |err|
192
- expect(err.message).to eq('missing dependency for Broken: cannot load such file -- zomg/i_dont/exist')
192
+ expect(err.message).to match(%r{missing dependency for Broken: .+ -- zomg/i_dont/exist})
193
193
  end
194
194
  end
195
195
  end
@@ -67,4 +67,17 @@ RSpec.describe Faraday::Request::UrlEncoded do
67
67
  response = conn.post('/echo', 'a' => { 'b' => { 'c' => ['d'] } })
68
68
  expect(response.body).to eq('a%5Bb%5D%5Bc%5D%5B%5D=d')
69
69
  end
70
+
71
+ context 'customising default_space_encoding' do
72
+ around do |example|
73
+ Faraday::Utils.default_space_encoding = '%20'
74
+ example.run
75
+ Faraday::Utils.default_space_encoding = nil
76
+ end
77
+
78
+ it 'uses the custom character to encode spaces' do
79
+ response = conn.post('/echo', str: 'apple banana')
80
+ expect(response.body).to eq('str=apple%20banana')
81
+ end
82
+ end
70
83
  end
@@ -26,6 +26,22 @@ RSpec.describe Faraday::Response::Middleware do
26
26
  end
27
27
  end
28
28
 
29
+ context 'with a custom ResponseMiddleware and private parse' do
30
+ let(:custom_middleware) do
31
+ Class.new(Faraday::Response::Middleware) do
32
+ private
33
+
34
+ def parse(body)
35
+ body.upcase
36
+ end
37
+ end
38
+ end
39
+
40
+ it 'parses the response' do
41
+ expect(conn.get('ok').body).to eq('<BODY></BODY>')
42
+ end
43
+ end
44
+
29
45
  context 'with a custom ResponseMiddleware but empty response' do
30
46
  let(:custom_middleware) do
31
47
  Class.new(Faraday::Response::Middleware) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "@technoweenie"
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-01-01 00:00:00.000000000 Z
13
+ date: 2020-03-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multipart-post
@@ -42,7 +42,6 @@ files:
42
42
  - LICENSE.md
43
43
  - README.md
44
44
  - Rakefile
45
- - UPGRADING.md
46
45
  - examples/client_spec.rb
47
46
  - examples/client_test.rb
48
47
  - lib/faraday.rb
@@ -143,13 +142,14 @@ licenses:
143
142
  - MIT
144
143
  metadata:
145
144
  homepage_uri: https://lostisland.github.io/faraday
146
- changelog_uri: https://github.com/lostisland/faraday/releases/tag/v1.0.0
145
+ changelog_uri: https://github.com/lostisland/faraday/releases/tag/v1.0.1
147
146
  source_code_uri: https://github.com/lostisland/faraday
148
147
  bug_tracker_uri: https://github.com/lostisland/faraday/issues
149
148
  post_install_message:
150
149
  rdoc_options: []
151
150
  require_paths:
152
151
  - lib
152
+ - spec/external_adapters
153
153
  required_ruby_version: !ruby/object:Gem::Requirement
154
154
  requirements:
155
155
  - - ">="
@@ -161,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
161
  - !ruby/object:Gem::Version
162
162
  version: '0'
163
163
  requirements: []
164
- rubygems_version: 3.1.2
164
+ rubygems_version: 3.0.3
165
165
  signing_key:
166
166
  specification_version: 4
167
167
  summary: HTTP/REST API client library.
@@ -1,55 +0,0 @@
1
- ## Faraday 1.0
2
-
3
- ### Errors
4
- * Removes sub-class constants definition from `Faraday::Error`. A sub-class (e.g. `ClientError`) was previously accessible
5
- either through the `Faraday` module (e.g. `Faraday::ClientError`) or through the `Faraday::Error` class (e.g. `Faraday::Error::ClientError`).
6
- The latter is no longer available and the former should be used instead, so check your `rescue`s.
7
- * Introduces a new `Faraday::ServerError` (5xx status codes) alongside the existing `Faraday::ClientError` (4xx status codes).
8
- Please note `Faraday::ClientError` was previously used for both.
9
- * Introduces new Errors that describe the most common REST status codes:
10
- * Faraday::BadRequestError (400)
11
- * Faraday::UnauthorizedError (401)
12
- * Faraday::ForbiddenError (403)
13
- * Faraday::ProxyAuthError (407). Please note this raised a `Faraday::ConnectionFailed` before.
14
- * Faraday::ConflictError (409)
15
- * Faraday::UnprocessableEntityError (422)
16
- * The following error classes have changed the hierarchy to better mirror their real-world usage and semantic meaning:
17
- * TimeoutError < ServerError (was < ClientError)
18
- * ConnectionFailed < Error (was < ClientError)
19
- * SSLError < Error (was < ClientError)
20
- * ParsingError < Error (was < ClientError)
21
- * RetriableResponse < Error (was < ClientError)
22
-
23
- ### Custom adapters
24
- If you have written a custom adapter, please be aware that `env.body` is now an alias to the two new properties `request_body` and `response_body`.
25
- This should work without you noticing if your adapter inherits from `Faraday::Adapter` and calls `save_response`, but if it doesn't, then please ensure you set the `status` BEFORE the `body` while processing the response.
26
-
27
- ### Others
28
- * Dropped support for jruby and Rubinius.
29
- * Officially supports Ruby 2.4+
30
- * In order to specify the adapter you now MUST use the `#adapter` method on the connection builder. If you don't do so and your adapter inherits from `Faraday::Adapter` then Faraday will raise an exception. Otherwise, Faraday will automatically push the default adapter at the end of the stack causing your request to be executed twice.
31
- ```ruby
32
- class OfficialAdapter < Faraday::Adapter
33
- ...
34
- end
35
-
36
- class MyAdapter
37
- ...
38
- end
39
-
40
- # This will raise an exception
41
- conn = Faraday.new(...) do |f|
42
- f.use OfficialAdapter
43
- end
44
-
45
- # This will cause Faraday inserting the default adapter at the end of the stack
46
- conn = Faraday.new(...) do |f|
47
- f.use MyAdapter
48
- end
49
-
50
- # You MUST use `adapter` method
51
- conn = Faraday.new(...) do |f|
52
- f.adapter AnyAdapter
53
- end
54
- ```
55
-