faraday-net_http 1.0.1 → 3.0.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: 4efc5a5f90fde405f695b602850c1060a683bc2ae350f8244637895cf414a7b1
4
+ data.tar.gz: b24f51c181e5dfda23f6687347b012cbfd3d225f9c9a4310ea5b69c8277c2f3c
5
5
  SHA512:
6
- metadata.gz: 13c56f77c7bad337f780d7651479550a1f4a639eb33612c32eb76480337de2d024e531d7b22f0a8b12f4f5f787986cff208e4e5f606ec74ee4de81fe00a8458b
7
- data.tar.gz: aa3eee27950f2fc19a9a53da24ad00c66ffaf4f31b97dc110f225ccdb99d851b15a8024e70f4b6445ab026621b6a04f87e7593d178ecf5efc0673b2ef3896088
6
+ metadata.gz: 828b85c9ec2c8d81f48749802a572af232574a124b16d245e903ecba162327a8b7107a046ea1f136105e6aa382a612efda5afb9dd49442d73b8f4884875f3a3e
7
+ data.tar.gz: d4cac854ff1631ee53acadf70efb2fa29608c4454e3b6a87b291c45152761cbe5ab99b98d929cc95256498631a456e677ac43be3b400b74a7a315bdedf0c9001
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,41 @@ 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
- else
122
- request_with_wrapped_block(http, env)
123
- end
124
- end
125
-
126
- 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
101
  else
131
- request_via_request_method(http, env, &block)
102
+ http_response = request_with_wrapped_block(http, env)
132
103
  end
104
+ env.response_body = encoded_body(http_response)
105
+ env.response.finish(env)
106
+ http_response
133
107
  end
134
108
 
135
- def request_via_get_method(http, env, &block)
109
+ def request_with_wrapped_block(http, env)
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
+ if block_given?
117
+ response.read_body do |chunk|
118
+ yield(chunk)
119
+ end
120
+ end
121
+ end
140
122
  end
141
123
  end
142
124
 
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)
125
+ def save_http_response(env, http_response)
126
+ save_response(
127
+ env, http_response.code.to_i, nil, nil, http_response.message, finished: false
128
+ ) do |response_headers|
129
+ http_response.each_header do |key, value|
130
+ response_headers[key] = value
153
131
  end
154
132
  end
155
133
  end
@@ -168,6 +146,7 @@ module Faraday
168
146
  http.ssl_version = ssl[:version] if ssl[:version]
169
147
  http.min_version = ssl[:min_version] if ssl[:min_version]
170
148
  http.max_version = ssl[:max_version] if ssl[:max_version]
149
+ http.verify_hostname = ssl[:verify_hostname] if verify_hostname_enabled?(http, ssl)
171
150
  end
172
151
 
173
152
  def configure_request(http, req)
@@ -208,6 +187,22 @@ module Faraday
208
187
  end
209
188
  end
210
189
  end
190
+
191
+ def encoded_body(http_response)
192
+ body = http_response.body || +''
193
+ /\bcharset=\s*(.+?)\s*(;|$)/.match(http_response['Content-Type']) do |match|
194
+ content_charset = ::Encoding.find(match.captures.first)
195
+ body = body.dup if body.frozen?
196
+ body.force_encoding(content_charset)
197
+ rescue ArgumentError
198
+ nil
199
+ end
200
+ body
201
+ end
202
+
203
+ def verify_hostname_enabled?(http, ssl)
204
+ http.respond_to?(:verify_hostname=) && ssl.key?(:verify_hostname)
205
+ end
211
206
  end
212
207
  end
213
208
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Faraday
4
4
  module NetHttp
5
- VERSION = '1.0.1'
5
+ VERSION = '3.0.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,29 @@
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.0.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: 2022-08-08 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'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
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
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '1.0'
26
+ version: '2.5'
153
27
  description: Faraday adapter for Net::HTTP
154
28
  email:
155
29
  - janvanderpas@gmail.com
@@ -168,7 +42,7 @@ licenses:
168
42
  metadata:
169
43
  homepage_uri: https://github.com/lostisland/faraday-net_http
170
44
  source_code_uri: https://github.com/lostisland/faraday-net_http
171
- changelog_uri: https://github.com/lostisland/faraday-net_http
45
+ changelog_uri: https://github.com/lostisland/faraday-net_http/releases/tag/v3.0.0
172
46
  post_install_message:
173
47
  rdoc_options: []
174
48
  require_paths:
@@ -177,14 +51,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
51
  requirements:
178
52
  - - ">="
179
53
  - !ruby/object:Gem::Version
180
- version: 2.4.0
54
+ version: 2.6.0
181
55
  required_rubygems_version: !ruby/object:Gem::Requirement
182
56
  requirements:
183
57
  - - ">="
184
58
  - !ruby/object:Gem::Version
185
59
  version: '0'
186
60
  requirements: []
187
- rubygems_version: 3.1.4
61
+ rubygems_version: 3.1.6
188
62
  signing_key:
189
63
  specification_version: 4
190
64
  summary: Faraday adapter for Net::HTTP