faraday-net_http 2.1.0 → 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: e471698764d66a8adfeafe9e3bad0472da1548fd4607ad5558b67cfce4932b02
4
- data.tar.gz: 8cac9b619ce0ed8fbc861e5f4dfc46339dd61b066ec685bd6bda5deaa0c13456
3
+ metadata.gz: 2d9a033eff57867fb6f0d7ef439a1a218ce10dcfad224979f1af82f96e8fa201
4
+ data.tar.gz: bce85e35b8871f4ec9ba42410043bd74608ce577ea5221f4397ee0929b2be03b
5
5
  SHA512:
6
- metadata.gz: afd126506d6c8c2110cd71a561ae0923ae32946ec437ad2cc5acc04ee1b50c2a2a7ac4cb1cf0752b0f9afae4f1227fa7d0e5e7693dd1c478a5c9f03be5923d45
7
- data.tar.gz: e9cbb0a9571ca1eefb2b30cbc02b45939272447dd976ff36f079b0f09d8adc2faaef0e0e918c552359e51ca85c69e1881616af516eaf30be96228b99b91ea2de
6
+ metadata.gz: 733173b97da6b8f8043dec130ddabb32f7f5e94673a095029d5d52b9b74326f34dee5fd2a6fcbcb91908d6168bce08ae22b2997d1c8e2124de3680f5c9e60bc4
7
+ data.tar.gz: e845d5bd38188d95f680a42b3ab78c06e8c485dcb27a6768ad4f4366208ca176b24db1ef657bfd3cb5c72c9b32440b4d536910bba36a454bfea52214a68f08a1
@@ -62,22 +62,13 @@ module Faraday
62
62
 
63
63
  def call(env)
64
64
  super
65
- http_response = connection(env) do |http|
65
+ connection(env) do |http|
66
66
  perform_request(http, env)
67
67
  rescue *NET_HTTP_EXCEPTIONS => e
68
68
  raise Faraday::SSLError, e if defined?(OpenSSL) && e.is_a?(OpenSSL::SSL::SSLError)
69
69
 
70
70
  raise Faraday::ConnectionFailed, e
71
71
  end
72
-
73
- save_response(env, http_response.code.to_i,
74
- encoded_body(http_response), nil,
75
- http_response.message) do |response_headers|
76
- http_response.each_header do |key, value|
77
- response_headers[key] = value
78
- end
79
- end
80
-
81
72
  @app.call env
82
73
  rescue Timeout::Error, Errno::ETIMEDOUT => e
83
74
  raise Faraday::TimeoutError, e
@@ -102,53 +93,37 @@ module Faraday
102
93
  end
103
94
 
104
95
  def perform_request(http, env)
105
- if env[:request].stream_response?
106
- size = 0
107
- yielded = false
108
- http_response = request_with_wrapped_block(http, env) do |chunk|
109
- if chunk.bytesize.positive? || size.positive?
110
- yielded = true
111
- size += chunk.bytesize
112
- env[:request].on_data.call(chunk, size)
113
- end
96
+ if env.stream_response?
97
+ http_response = env.stream_response do |&on_data|
98
+ request_with_wrapped_block(http, env, &on_data)
114
99
  end
115
- env[:request].on_data.call(+'', 0) unless yielded
116
- # Net::HTTP returns something,
117
- # but it's not meaningful according to the docs.
118
100
  http_response.body = nil
119
- http_response
120
101
  else
121
- request_with_wrapped_block(http, env)
102
+ http_response = request_with_wrapped_block(http, env)
122
103
  end
104
+ env.response_body = encoded_body(http_response)
105
+ env.response.finish(env)
106
+ http_response
123
107
  end
124
108
 
125
109
  def request_with_wrapped_block(http, env, &block)
126
- if (env[:method] == :get) && !env[:body]
127
- # prefer `get` to `request` because the former handles gzip (ruby 1.9)
128
- request_via_get_method(http, env, &block)
129
- else
130
- request_via_request_method(http, env, &block)
131
- end
132
- end
133
-
134
- def request_via_get_method(http, env, &block)
135
110
  # Must use Net::HTTP#start and pass it a block otherwise the server's
136
111
  # TCP socket does not close correctly.
137
112
  http.start do |opened_http|
138
- 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
139
118
  end
140
119
  end
141
120
 
142
- def request_via_request_method(http, env, &block)
143
- # Must use Net::HTTP#start and pass it a block otherwise the server's
144
- # TCP socket does not close correctly.
145
- http.start do |opened_http|
146
- if block_given?
147
- opened_http.request create_request(env) do |response|
148
- response.read_body(&block)
149
- end
150
- else
151
- 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
152
127
  end
153
128
  end
154
129
  end
@@ -193,26 +168,24 @@ 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
210
183
  end
211
184
 
212
185
  def encoded_body(http_response)
213
186
  body = http_response.body || +''
214
- /\bcharset=\s*(.+?)\s*(;|$)/.match(http_response['Content-Type']) do |match|
215
- content_charset = ::Encoding.find(match.captures.first)
187
+ /\bcharset=([^;]+)/.match(http_response['Content-Type']) do |match|
188
+ content_charset = ::Encoding.find(match[1].strip)
216
189
  body = body.dup if body.frozen?
217
190
  body.force_encoding(content_charset)
218
191
  rescue ArgumentError
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Faraday
4
4
  module NetHttp
5
- VERSION = '2.1.0'
5
+ VERSION = '3.1.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.1.0
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: 2022-07-28 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
@@ -16,14 +16,28 @@ 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
+ - !ruby/object:Gem::Dependency
28
+ name: net-http
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: Faraday adapter for Net::HTTP
28
42
  email:
29
43
  - janvanderpas@gmail.com
@@ -42,7 +56,7 @@ licenses:
42
56
  metadata:
43
57
  homepage_uri: https://github.com/lostisland/faraday-net_http
44
58
  source_code_uri: https://github.com/lostisland/faraday-net_http
45
- changelog_uri: https://github.com/lostisland/faraday-net_http/releases/tag/v2.1.0
59
+ changelog_uri: https://github.com/lostisland/faraday-net_http/releases/tag/v3.1.0
46
60
  post_install_message:
47
61
  rdoc_options: []
48
62
  require_paths:
@@ -51,14 +65,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
- version: 2.4.0
68
+ version: 3.0.0
55
69
  required_rubygems_version: !ruby/object:Gem::Requirement
56
70
  requirements:
57
71
  - - ">="
58
72
  - !ruby/object:Gem::Version
59
73
  version: '0'
60
74
  requirements: []
61
- rubygems_version: 3.1.6
75
+ rubygems_version: 3.5.3
62
76
  signing_key:
63
77
  specification_version: 4
64
78
  summary: Faraday adapter for Net::HTTP