faraday-net_http 1.0.1 → 3.1.0

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: abc66839ab88c5fc96b602b163b00c896eaee90a533db6464dbe38aa763f857f
4
- data.tar.gz: a26950415c34a093595c44b34dcd79af3efa5d9513097444e478467e882fa787
3
+ metadata.gz: 2d9a033eff57867fb6f0d7ef439a1a218ce10dcfad224979f1af82f96e8fa201
4
+ data.tar.gz: bce85e35b8871f4ec9ba42410043bd74608ce577ea5221f4397ee0929b2be03b
5
5
  SHA512:
6
- metadata.gz: 13c56f77c7bad337f780d7651479550a1f4a639eb33612c32eb76480337de2d024e531d7b22f0a8b12f4f5f787986cff208e4e5f606ec74ee4de81fe00a8458b
7
- data.tar.gz: aa3eee27950f2fc19a9a53da24ad00c66ffaf4f31b97dc110f225ccdb99d851b15a8024e70f4b6445ab026621b6a04f87e7593d178ecf5efc0673b2ef3896088
6
+ metadata.gz: 733173b97da6b8f8043dec130ddabb32f7f5e94673a095029d5d52b9b74326f34dee5fd2a6fcbcb91908d6168bce08ae22b2997d1c8e2124de3680f5c9e60bc4
7
+ data.tar.gz: e845d5bd38188d95f680a42b3ab78c06e8c485dcb27a6768ad4f4366208ca176b24db1ef657bfd3cb5c72c9b32440b4d536910bba36a454bfea52214a68f08a1
data/README.md CHANGED
@@ -20,16 +20,17 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- Configure your Faraday connection to use this adapter like this:
24
-
25
23
  ```ruby
26
- connection = Faraday.new(url, conn_options) do |conn|
27
- conn.adapter(:net_http)
24
+ conn = Faraday.new(...) do |f|
25
+ f.adapter :net_http do |http|
26
+ # yields Net::HTTP
27
+ http.verify_callback = lambda do |preverify, cert_store|
28
+ # do something here...
29
+ end
30
+ end
28
31
  end
29
32
  ```
30
33
 
31
- For more information on how to setup your Faraday connection and adapters usage, please refer to the [Faraday Website][faraday-website].
32
-
33
34
  ## Development
34
35
 
35
36
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -49,9 +50,8 @@ The gem is available as open source under the terms of the [license][license].
49
50
  Everyone interacting in the Faraday Net::HTTP adapter project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct][code-of-conduct].
50
51
 
51
52
  [faraday]: https://github.com/lostisland/faraday
52
- [faraday-website]: https://lostisland.github.io/faraday
53
53
  [net-http]: https://ruby-doc.org/stdlib-2.7.0/libdoc/net/http/rdoc/Net/HTTP.html
54
54
  [rubygems]: https://rubygems.org
55
55
  [repo]: https://github.com/lostisland/faraday-net_http
56
56
  [license]: https://github.com/lostisland/faraday-net_http/blob/main/LICENSE.md
57
- [code-of-conduct]: https://github.com/lostisland/faraday-net_http/blob/main/CODE_OF_CONDUCT.md
57
+ [code-of-conduct]: https://github.com/lostisland/faraday-net_http/blob/main/CODE_OF_CONDUCT.md
@@ -15,6 +15,7 @@ module Faraday
15
15
  exceptions = [
16
16
  IOError,
17
17
  Errno::EADDRNOTAVAIL,
18
+ Errno::EALREADY,
18
19
  Errno::ECONNABORTED,
19
20
  Errno::ECONNREFUSED,
20
21
  Errno::ECONNRESET,
@@ -61,24 +62,13 @@ module Faraday
61
62
 
62
63
  def call(env)
63
64
  super
64
- http_response = connection(env) do |http|
65
- begin
66
- perform_request(http, env)
67
- rescue *NET_HTTP_EXCEPTIONS => e
68
- raise Faraday::SSLError, e if defined?(OpenSSL) && e.is_a?(OpenSSL::SSL::SSLError)
65
+ connection(env) do |http|
66
+ perform_request(http, env)
67
+ rescue *NET_HTTP_EXCEPTIONS => e
68
+ raise Faraday::SSLError, e if defined?(OpenSSL) && e.is_a?(OpenSSL::SSL::SSLError)
69
69
 
70
- raise Faraday::ConnectionFailed, e
71
- end
70
+ raise Faraday::ConnectionFailed, e
72
71
  end
73
-
74
- save_response(env, http_response.code.to_i,
75
- http_response.body || +'', nil,
76
- http_response.message) do |response_headers|
77
- http_response.each_header do |key, value|
78
- response_headers[key] = value
79
- end
80
- end
81
-
82
72
  @app.call env
83
73
  rescue Timeout::Error, Errno::ETIMEDOUT => e
84
74
  raise Faraday::TimeoutError, e
@@ -103,53 +93,37 @@ module Faraday
103
93
  end
104
94
 
105
95
  def perform_request(http, env)
106
- if env[:request].stream_response?
107
- size = 0
108
- yielded = false
109
- http_response = request_with_wrapped_block(http, env) do |chunk|
110
- if chunk.bytesize.positive? || size.positive?
111
- yielded = true
112
- size += chunk.bytesize
113
- env[:request].on_data.call(chunk, size)
114
- end
96
+ if env.stream_response?
97
+ http_response = env.stream_response do |&on_data|
98
+ request_with_wrapped_block(http, env, &on_data)
115
99
  end
116
- env[:request].on_data.call(+'', 0) unless yielded
117
- # Net::HTTP returns something,
118
- # but it's not meaningful according to the docs.
119
100
  http_response.body = nil
120
- http_response
121
101
  else
122
- request_with_wrapped_block(http, env)
102
+ http_response = request_with_wrapped_block(http, env)
123
103
  end
104
+ env.response_body = encoded_body(http_response)
105
+ env.response.finish(env)
106
+ http_response
124
107
  end
125
108
 
126
109
  def request_with_wrapped_block(http, env, &block)
127
- if (env[:method] == :get) && !env[:body]
128
- # prefer `get` to `request` because the former handles gzip (ruby 1.9)
129
- request_via_get_method(http, env, &block)
130
- else
131
- request_via_request_method(http, env, &block)
132
- end
133
- end
134
-
135
- def request_via_get_method(http, env, &block)
136
110
  # Must use Net::HTTP#start and pass it a block otherwise the server's
137
111
  # TCP socket does not close correctly.
138
112
  http.start do |opened_http|
139
- opened_http.get env[:url].request_uri, env[:request_headers], &block
113
+ opened_http.request create_request(env) do |response|
114
+ save_http_response(env, response)
115
+
116
+ response.read_body(&block) if block_given?
117
+ end
140
118
  end
141
119
  end
142
120
 
143
- def request_via_request_method(http, env, &block)
144
- # Must use Net::HTTP#start and pass it a block otherwise the server's
145
- # TCP socket does not close correctly.
146
- http.start do |opened_http|
147
- if block_given?
148
- opened_http.request create_request(env) do |response|
149
- response.read_body(&block)
150
- end
151
- else
152
- opened_http.request create_request(env)
121
+ def save_http_response(env, http_response)
122
+ save_response(
123
+ env, http_response.code.to_i, nil, nil, http_response.message, finished: false
124
+ ) do |response_headers|
125
+ http_response.each_header do |key, value|
126
+ response_headers[key] = value
153
127
  end
154
128
  end
155
129
  end
@@ -168,6 +142,7 @@ module Faraday
168
142
  http.ssl_version = ssl[:version] if ssl[:version]
169
143
  http.min_version = ssl[:min_version] if ssl[:min_version]
170
144
  http.max_version = ssl[:max_version] if ssl[:max_version]
145
+ http.verify_hostname = ssl[:verify_hostname] if verify_hostname_enabled?(http, ssl)
171
146
  end
172
147
 
173
148
  def configure_request(http, req)
@@ -193,20 +168,34 @@ module Faraday
193
168
  def ssl_cert_store(ssl)
194
169
  return ssl[:cert_store] if ssl[:cert_store]
195
170
 
196
- @ssl_cert_store ||= begin
197
- # Use the default cert store by default, i.e. system ca certs
198
- OpenSSL::X509::Store.new.tap(&:set_default_paths)
199
- end
171
+ # Use the default cert store by default, i.e. system ca certs
172
+ @ssl_cert_store ||= OpenSSL::X509::Store.new.tap(&:set_default_paths)
200
173
  end
201
174
 
202
175
  def ssl_verify_mode(ssl)
203
176
  ssl[:verify_mode] || begin
204
- if ssl.fetch(:verify, true)
205
- OpenSSL::SSL::VERIFY_PEER
206
- else
207
- OpenSSL::SSL::VERIFY_NONE
208
- end
209
- end
177
+ if ssl.fetch(:verify, true)
178
+ OpenSSL::SSL::VERIFY_PEER
179
+ else
180
+ OpenSSL::SSL::VERIFY_NONE
181
+ end
182
+ end
183
+ end
184
+
185
+ def encoded_body(http_response)
186
+ body = http_response.body || +''
187
+ /\bcharset=([^;]+)/.match(http_response['Content-Type']) do |match|
188
+ content_charset = ::Encoding.find(match[1].strip)
189
+ body = body.dup if body.frozen?
190
+ body.force_encoding(content_charset)
191
+ rescue ArgumentError
192
+ nil
193
+ end
194
+ body
195
+ end
196
+
197
+ def verify_hostname_enabled?(http, ssl)
198
+ http.respond_to?(:verify_hostname=) && ssl.key?(:verify_hostname)
210
199
  end
211
200
  end
212
201
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Faraday
4
4
  module NetHttp
5
- VERSION = '1.0.1'
5
+ VERSION = '3.1.0'
6
6
  end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'adapter/net_http'
4
- require_relative 'net_http/version'
3
+ require 'faraday/adapter/net_http'
4
+ require 'faraday/net_http/version'
5
5
 
6
6
  module Faraday
7
7
  module NetHttp
metadata CHANGED
@@ -1,155 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday-net_http
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan van der Pas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-12 00:00:00.000000000 Z
11
+ date: 2024-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '2.5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.0'
26
+ version: '2.5'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: net-http
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '2.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '2.0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '13.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '13.0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '3.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '3.0'
69
- - !ruby/object:Gem::Dependency
70
- name: simplecov
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: 0.19.0
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: 0.19.0
83
- - !ruby/object:Gem::Dependency
84
- name: multipart-parser
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: 0.1.1
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: 0.1.1
97
- - !ruby/object:Gem::Dependency
98
- name: webmock
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '3.4'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '3.4'
111
- - !ruby/object:Gem::Dependency
112
- name: rubocop
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: 0.91.1
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: 0.91.1
125
- - !ruby/object:Gem::Dependency
126
- name: rubocop-packaging
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '0.5'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '0.5'
139
- - !ruby/object:Gem::Dependency
140
- name: rubocop-performance
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '1.0'
146
- type: :development
33
+ version: '0'
34
+ type: :runtime
147
35
  prerelease: false
148
36
  version_requirements: !ruby/object:Gem::Requirement
149
37
  requirements:
150
- - - "~>"
38
+ - - ">="
151
39
  - !ruby/object:Gem::Version
152
- version: '1.0'
40
+ version: '0'
153
41
  description: Faraday adapter for Net::HTTP
154
42
  email:
155
43
  - janvanderpas@gmail.com
@@ -168,7 +56,7 @@ licenses:
168
56
  metadata:
169
57
  homepage_uri: https://github.com/lostisland/faraday-net_http
170
58
  source_code_uri: https://github.com/lostisland/faraday-net_http
171
- changelog_uri: https://github.com/lostisland/faraday-net_http
59
+ changelog_uri: https://github.com/lostisland/faraday-net_http/releases/tag/v3.1.0
172
60
  post_install_message:
173
61
  rdoc_options: []
174
62
  require_paths:
@@ -177,14 +65,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
65
  requirements:
178
66
  - - ">="
179
67
  - !ruby/object:Gem::Version
180
- version: 2.4.0
68
+ version: 3.0.0
181
69
  required_rubygems_version: !ruby/object:Gem::Requirement
182
70
  requirements:
183
71
  - - ">="
184
72
  - !ruby/object:Gem::Version
185
73
  version: '0'
186
74
  requirements: []
187
- rubygems_version: 3.1.4
75
+ rubygems_version: 3.5.3
188
76
  signing_key:
189
77
  specification_version: 4
190
78
  summary: Faraday adapter for Net::HTTP