faraday-net_http 2.0.2 → 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: dd81d4fd0efd54bc9645740c95d58d1da812ea43be13b265f2a6031136b7d5d6
4
- data.tar.gz: 6b53df4188f50693d8f4c7ebb2fea9ae9a5f8277e0894ba49be7f2ceb90f95e0
3
+ metadata.gz: 4efc5a5f90fde405f695b602850c1060a683bc2ae350f8244637895cf414a7b1
4
+ data.tar.gz: b24f51c181e5dfda23f6687347b012cbfd3d225f9c9a4310ea5b69c8277c2f3c
5
5
  SHA512:
6
- metadata.gz: 8ac00145c8e0a0a9dbb53daf0a4da960d56143227293288b5b6c4754b302f3ad3123edebefdf987d4b4250f5473e2adf2c9267eb70f8c26e141c78f0c4a478d5
7
- data.tar.gz: e059ac1f6872511c4095136fa3b6e52fc130b303258bb4bb0a755fd5fc53ba8218e17e54ab56d3df1c92e936c416f673c7bbc1e600158eb87c503b0cab7af349
6
+ metadata.gz: 828b85c9ec2c8d81f48749802a572af232574a124b16d245e903ecba162327a8b7107a046ea1f136105e6aa382a612efda5afb9dd49442d73b8f4884875f3a3e
7
+ data.tar.gz: d4cac854ff1631ee53acadf70efb2fa29608c4454e3b6a87b291c45152761cbe5ab99b98d929cc95256498631a456e677ac43be3b400b74a7a315bdedf0c9001
data/README.md CHANGED
@@ -24,7 +24,6 @@ Or install it yourself as:
24
24
  conn = Faraday.new(...) do |f|
25
25
  f.adapter :net_http do |http|
26
26
  # yields Net::HTTP
27
- http.idle_timeout = 100
28
27
  http.verify_callback = lambda do |preverify, cert_store|
29
28
  # do something here...
30
29
  end
@@ -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,22 +62,13 @@ module Faraday
61
62
 
62
63
  def call(env)
63
64
  super
64
- http_response = connection(env) do |http|
65
+ connection(env) do |http|
65
66
  perform_request(http, env)
66
67
  rescue *NET_HTTP_EXCEPTIONS => e
67
68
  raise Faraday::SSLError, e if defined?(OpenSSL) && e.is_a?(OpenSSL::SSL::SSLError)
68
69
 
69
70
  raise Faraday::ConnectionFailed, e
70
71
  end
71
-
72
- save_response(env, http_response.code.to_i,
73
- encoded_body(http_response), nil,
74
- http_response.message) do |response_headers|
75
- http_response.each_header do |key, value|
76
- response_headers[key] = value
77
- end
78
- end
79
-
80
72
  @app.call env
81
73
  rescue Timeout::Error, Errno::ETIMEDOUT => e
82
74
  raise Faraday::TimeoutError, e
@@ -101,53 +93,41 @@ module Faraday
101
93
  end
102
94
 
103
95
  def perform_request(http, env)
104
- if env[:request].stream_response?
105
- size = 0
106
- yielded = false
107
- http_response = request_with_wrapped_block(http, env) do |chunk|
108
- if chunk.bytesize.positive? || size.positive?
109
- yielded = true
110
- size += chunk.bytesize
111
- env[:request].on_data.call(chunk, size)
112
- end
96
+ if env.stream_response?
97
+ http_response = env.stream_response do |&on_data|
98
+ request_with_wrapped_block(http, env, &on_data)
113
99
  end
114
- env[:request].on_data.call(+'', 0) unless yielded
115
- # Net::HTTP returns something,
116
- # but it's not meaningful according to the docs.
117
100
  http_response.body = nil
118
- http_response
119
- else
120
- request_with_wrapped_block(http, env)
121
- end
122
- end
123
-
124
- def request_with_wrapped_block(http, env, &block)
125
- if (env[:method] == :get) && !env[:body]
126
- # prefer `get` to `request` because the former handles gzip (ruby 1.9)
127
- request_via_get_method(http, env, &block)
128
101
  else
129
- request_via_request_method(http, env, &block)
102
+ http_response = request_with_wrapped_block(http, env)
130
103
  end
104
+ env.response_body = encoded_body(http_response)
105
+ env.response.finish(env)
106
+ http_response
131
107
  end
132
108
 
133
- def request_via_get_method(http, env, &block)
109
+ def request_with_wrapped_block(http, env)
134
110
  # Must use Net::HTTP#start and pass it a block otherwise the server's
135
111
  # TCP socket does not close correctly.
136
112
  http.start do |opened_http|
137
- 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
138
122
  end
139
123
  end
140
124
 
141
- def request_via_request_method(http, env, &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
- if block_given?
146
- opened_http.request create_request(env) do |response|
147
- response.read_body(&block)
148
- end
149
- else
150
- 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
151
131
  end
152
132
  end
153
133
  end
@@ -166,6 +146,7 @@ module Faraday
166
146
  http.ssl_version = ssl[:version] if ssl[:version]
167
147
  http.min_version = ssl[:min_version] if ssl[:min_version]
168
148
  http.max_version = ssl[:max_version] if ssl[:max_version]
149
+ http.verify_hostname = ssl[:verify_hostname] if verify_hostname_enabled?(http, ssl)
169
150
  end
170
151
 
171
152
  def configure_request(http, req)
@@ -218,6 +199,10 @@ module Faraday
218
199
  end
219
200
  body
220
201
  end
202
+
203
+ def verify_hostname_enabled?(http, ssl)
204
+ http.respond_to?(:verify_hostname=) && ssl.key?(:verify_hostname)
205
+ end
221
206
  end
222
207
  end
223
208
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Faraday
4
4
  module NetHttp
5
- VERSION = '2.0.2'
5
+ VERSION = '3.0.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday-net_http
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
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: 2022-04-10 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
@@ -16,14 +16,14 @@ dependencies:
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
  description: Faraday adapter for Net::HTTP
28
28
  email:
29
29
  - janvanderpas@gmail.com
@@ -42,7 +42,7 @@ licenses:
42
42
  metadata:
43
43
  homepage_uri: https://github.com/lostisland/faraday-net_http
44
44
  source_code_uri: https://github.com/lostisland/faraday-net_http
45
- changelog_uri: https://github.com/lostisland/faraday-net_http/releases/tag/v2.0.2
45
+ changelog_uri: https://github.com/lostisland/faraday-net_http/releases/tag/v3.0.0
46
46
  post_install_message:
47
47
  rdoc_options: []
48
48
  require_paths:
@@ -51,7 +51,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 2.4.0
54
+ version: 2.6.0
55
55
  required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - ">="