faraday-net_http 2.1.0 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/faraday/adapter/net_http.rb +26 -47
- data/lib/faraday/net_http/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cad2197cf7df07a668741fb5ae27309b6f7aee396b207268ba63076569ae59f
|
4
|
+
data.tar.gz: 47fbe72a4c70f85b5659376f0a758088d26c8a6f2901a8320a22bfba872e2c1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b6cb45789018beedcef079c136c213e6532aba87d2503bd6f1544cf30f3ab3cdda9c08e4164d0f93a056595622cdf9c8f125e19798f8147e3e52f1387c5c800
|
7
|
+
data.tar.gz: 66131665eb559ad8b1bbba18c12916c3ace677b93a6055269c7def945dced9021f2864df22d9326880a8379602e0ac78fd44f49c137217e05978fa7377cedb3d
|
@@ -62,22 +62,13 @@ module Faraday
|
|
62
62
|
|
63
63
|
def call(env)
|
64
64
|
super
|
65
|
-
|
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
|
106
|
-
|
107
|
-
|
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
|
-
|
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
|
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.
|
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
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
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
|
215
|
-
content_charset = ::Encoding.find(match.
|
193
|
+
/\bcharset=([^;]+)/.match(http_response['Content-Type']) do |match|
|
194
|
+
content_charset = ::Encoding.find(match[1].strip)
|
216
195
|
body = body.dup if body.frozen?
|
217
196
|
body.force_encoding(content_charset)
|
218
197
|
rescue ArgumentError
|
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:
|
4
|
+
version: 3.0.2
|
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-
|
11
|
+
date: 2022-11-11 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: '
|
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: '
|
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/
|
45
|
+
changelog_uri: https://github.com/lostisland/faraday-net_http/releases/tag/v3.0.2
|
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.
|
54
|
+
version: 2.6.0
|
55
55
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
57
|
- - ">="
|