faraday-net_http 2.1.0 → 3.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: e471698764d66a8adfeafe9e3bad0472da1548fd4607ad5558b67cfce4932b02
4
- data.tar.gz: 8cac9b619ce0ed8fbc861e5f4dfc46339dd61b066ec685bd6bda5deaa0c13456
3
+ metadata.gz: 6dceca36c2e49d9e2642dd7d6177df8ee20d799efb59a2ae661a2790f05244a9
4
+ data.tar.gz: c064e33f9fa0666b1b7402f5bb948401fd76c78205d627942b5e693b271fbaed
5
5
  SHA512:
6
- metadata.gz: afd126506d6c8c2110cd71a561ae0923ae32946ec437ad2cc5acc04ee1b50c2a2a7ac4cb1cf0752b0f9afae4f1227fa7d0e5e7693dd1c478a5c9f03be5923d45
7
- data.tar.gz: e9cbb0a9571ca1eefb2b30cbc02b45939272447dd976ff36f079b0f09d8adc2faaef0e0e918c552359e51ca85c69e1881616af516eaf30be96228b99b91ea2de
6
+ metadata.gz: 4b49ece078d46b76578f63b8efefeff9b10cade3eb71850583b5f1902f60aab105cbc4a81581718e33f0cb7a12357a07bf8f0440832aa85044adfbcd7a5cea2a
7
+ data.tar.gz: 365a1b68e1f2bde815155b9836a281705ba6806155363245cc3ca837d6a3bfb014c4b8f0bd46984c52783f73a1f7957c2dd8ab6f39b84c639e15b4beae7b9a56
@@ -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,41 @@ 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
- else
121
- request_with_wrapped_block(http, env)
122
- end
123
- end
124
-
125
- 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
101
  else
130
- request_via_request_method(http, env, &block)
102
+ http_response = request_with_wrapped_block(http, env)
131
103
  end
104
+ env.response_body = encoded_body(http_response)
105
+ env.response.finish(env)
106
+ http_response
132
107
  end
133
108
 
134
- def request_via_get_method(http, env, &block)
109
+ def request_with_wrapped_block(http, env)
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
+ if block_given?
117
+ response.read_body do |chunk|
118
+ yield(chunk)
119
+ end
120
+ end
121
+ end
139
122
  end
140
123
  end
141
124
 
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)
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
152
131
  end
153
132
  end
154
133
  end
@@ -211,8 +190,8 @@ module Faraday
211
190
 
212
191
  def encoded_body(http_response)
213
192
  body = http_response.body || +''
214
- /\bcharset=\s*(.+?)\s*(;|$)/.match(http_response['Content-Type']) do |match|
215
- content_charset = ::Encoding.find(match.captures.first)
193
+ /\bcharset=(.+)/.match(http_response['Content-Type']) do |match|
194
+ content_charset = ::Encoding.find(match.captures.first.split(';').first.strip)
216
195
  body = body.dup if body.frozen?
217
196
  body.force_encoding(content_charset)
218
197
  rescue ArgumentError
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Faraday
4
4
  module NetHttp
5
- VERSION = '2.1.0'
5
+ VERSION = '3.0.1'
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.0.1
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: 2022-10-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.1.0
45
+ changelog_uri: https://github.com/lostisland/faraday-net_http/releases/tag/v3.0.1
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
  - - ">="