faraday 1.0.0.pre.rc1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +276 -0
- data/README.md +4 -4
- data/Rakefile +7 -0
- data/UPGRADING.md +55 -0
- data/examples/client_spec.rb +65 -0
- data/examples/client_test.rb +79 -0
- data/lib/faraday.rb +4 -4
- data/lib/faraday/adapter.rb +46 -0
- data/lib/faraday/adapter/em_http.rb +5 -6
- data/lib/faraday/adapter/em_http_ssl_patch.rb +1 -1
- data/lib/faraday/adapter/excon.rb +24 -22
- data/lib/faraday/adapter/httpclient.rb +40 -39
- data/lib/faraday/adapter/net_http.rb +42 -38
- data/lib/faraday/adapter/net_http_persistent.rb +3 -1
- data/lib/faraday/adapter/patron.rb +42 -24
- data/lib/faraday/adapter/rack.rb +2 -1
- data/lib/faraday/connection.rb +10 -22
- data/lib/faraday/encoders/flat_params_encoder.rb +7 -3
- data/lib/faraday/error.rb +44 -12
- data/lib/faraday/{upload_io.rb → file_part.rb} +53 -3
- data/lib/faraday/logging/formatter.rb +28 -15
- data/lib/faraday/middleware.rb +8 -0
- data/lib/faraday/options.rb +1 -1
- data/lib/faraday/options/env.rb +1 -1
- data/lib/faraday/options/request_options.rb +3 -2
- data/lib/faraday/param_part.rb +53 -0
- data/lib/faraday/request/multipart.rb +9 -1
- data/lib/faraday/response.rb +2 -2
- data/lib/faraday/response/raise_error.rb +2 -0
- data/spec/faraday/adapter/em_http_spec.rb +47 -0
- data/spec/faraday/adapter/em_synchrony_spec.rb +16 -0
- data/spec/faraday/adapter/excon_spec.rb +49 -0
- data/spec/faraday/adapter/httpclient_spec.rb +73 -0
- data/spec/faraday/adapter/net_http_persistent_spec.rb +57 -0
- data/spec/faraday/adapter/net_http_spec.rb +64 -0
- data/spec/faraday/adapter/patron_spec.rb +18 -0
- data/spec/faraday/adapter/rack_spec.rb +8 -0
- data/spec/faraday/adapter/typhoeus_spec.rb +7 -0
- data/spec/faraday/adapter_registry_spec.rb +28 -0
- data/spec/faraday/adapter_spec.rb +55 -0
- data/spec/faraday/composite_read_io_spec.rb +80 -0
- data/spec/faraday/connection_spec.rb +691 -0
- data/spec/faraday/error_spec.rb +45 -0
- data/spec/faraday/middleware_spec.rb +26 -0
- data/spec/faraday/options/env_spec.rb +70 -0
- data/spec/faraday/options/options_spec.rb +297 -0
- data/spec/faraday/options/proxy_options_spec.rb +37 -0
- data/spec/faraday/options/request_options_spec.rb +19 -0
- data/spec/faraday/params_encoders/flat_spec.rb +34 -0
- data/spec/faraday/params_encoders/nested_spec.rb +134 -0
- data/spec/faraday/rack_builder_spec.rb +196 -0
- data/spec/faraday/request/authorization_spec.rb +88 -0
- data/spec/faraday/request/instrumentation_spec.rb +76 -0
- data/spec/faraday/request/multipart_spec.rb +274 -0
- data/spec/faraday/request/retry_spec.rb +242 -0
- data/spec/faraday/request/url_encoded_spec.rb +70 -0
- data/spec/faraday/request_spec.rb +109 -0
- data/spec/faraday/response/logger_spec.rb +220 -0
- data/spec/faraday/response/middleware_spec.rb +52 -0
- data/spec/faraday/response/raise_error_spec.rb +106 -0
- data/spec/faraday/response_spec.rb +75 -0
- data/spec/faraday/utils/headers_spec.rb +82 -0
- data/spec/faraday/utils_spec.rb +56 -0
- data/spec/faraday_spec.rb +37 -0
- data/spec/spec_helper.rb +132 -0
- data/spec/support/disabling_stub.rb +14 -0
- data/spec/support/fake_safe_buffer.rb +15 -0
- data/spec/support/helper_methods.rb +133 -0
- data/spec/support/shared_examples/adapter.rb +104 -0
- data/spec/support/shared_examples/params_encoder.rb +18 -0
- data/spec/support/shared_examples/request_method.rb +234 -0
- data/spec/support/streaming_response_checker.rb +35 -0
- data/spec/support/webmock_rack_app.rb +68 -0
- metadata +65 -11
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
module StreamingResponseChecker
|
5
|
+
def check_streaming_response(streamed, options = {})
|
6
|
+
opts = {
|
7
|
+
prefix: '',
|
8
|
+
streaming?: true
|
9
|
+
}.merge(options)
|
10
|
+
|
11
|
+
expected_response = opts[:prefix] + big_string
|
12
|
+
|
13
|
+
chunks, sizes = streamed.transpose
|
14
|
+
|
15
|
+
# Check that the total size of the chunks (via the last size returned)
|
16
|
+
# is the same size as the expected_response
|
17
|
+
expect(sizes.last).to eq(expected_response.bytesize)
|
18
|
+
|
19
|
+
start_index = 0
|
20
|
+
expected_chunks = []
|
21
|
+
chunks.each do |actual_chunk|
|
22
|
+
expected_chunk = expected_response[start_index..((start_index + actual_chunk.bytesize) - 1)]
|
23
|
+
expected_chunks << expected_chunk
|
24
|
+
start_index += expected_chunk.bytesize
|
25
|
+
end
|
26
|
+
|
27
|
+
# it's easier to read a smaller portion, so we check that first
|
28
|
+
expect(expected_chunks[0][0..255]).to eq(chunks[0][0..255])
|
29
|
+
|
30
|
+
[expected_chunks, chunks].transpose.each do |expected, actual|
|
31
|
+
expect(actual).to eq(expected)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Rack app used to test the Rack adapter.
|
4
|
+
# Uses Webmock to check if requests are registered, in which case it returns
|
5
|
+
# the registered response.
|
6
|
+
class WebmockRackApp
|
7
|
+
def call(env)
|
8
|
+
req_signature = WebMock::RequestSignature.new(
|
9
|
+
req_method(env),
|
10
|
+
req_uri(env),
|
11
|
+
body: req_body(env),
|
12
|
+
headers: req_headers(env)
|
13
|
+
)
|
14
|
+
|
15
|
+
WebMock::RequestRegistry
|
16
|
+
.instance
|
17
|
+
.requested_signatures
|
18
|
+
.put(req_signature)
|
19
|
+
|
20
|
+
process_response(req_signature)
|
21
|
+
end
|
22
|
+
|
23
|
+
def req_method(env)
|
24
|
+
env['REQUEST_METHOD'].downcase.to_sym
|
25
|
+
end
|
26
|
+
|
27
|
+
def req_uri(env)
|
28
|
+
scheme = env['rack.url_scheme']
|
29
|
+
host = env['SERVER_NAME']
|
30
|
+
port = env['SERVER_PORT']
|
31
|
+
path = env['PATH_INFO']
|
32
|
+
query = env['QUERY_STRING']
|
33
|
+
|
34
|
+
url = +"#{scheme}://#{host}:#{port}#{path}"
|
35
|
+
url += "?#{query}" if query
|
36
|
+
|
37
|
+
uri = WebMock::Util::URI.heuristic_parse(url)
|
38
|
+
uri.path = uri.normalized_path.gsub('[^:]//', '/')
|
39
|
+
uri
|
40
|
+
end
|
41
|
+
|
42
|
+
def req_headers(env)
|
43
|
+
http_headers = env.select { |k, _| k.start_with?('HTTP_') }
|
44
|
+
.map { |k, v| [k[5..-1], v] }
|
45
|
+
.to_h
|
46
|
+
|
47
|
+
special_headers = Faraday::Adapter::Rack::SPECIAL_HEADERS
|
48
|
+
http_headers.merge(env.select { |k, _| special_headers.include?(k) })
|
49
|
+
end
|
50
|
+
|
51
|
+
def req_body(env)
|
52
|
+
env['rack.input'].read
|
53
|
+
end
|
54
|
+
|
55
|
+
def process_response(req_signature)
|
56
|
+
res = WebMock::StubRegistry.instance.response_for_request(req_signature)
|
57
|
+
|
58
|
+
if res.nil? && req_signature.uri.host == 'localhost'
|
59
|
+
raise Faraday::ConnectionFailed, 'Trying to connect to localhost'
|
60
|
+
end
|
61
|
+
|
62
|
+
raise WebMock::NetConnectNotAllowedError, req_signature unless res
|
63
|
+
|
64
|
+
raise Faraday::TimeoutError if res.should_timeout
|
65
|
+
|
66
|
+
[res.status[0], res.headers || {}, [res.body || '']]
|
67
|
+
end
|
68
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- "@technoweenie"
|
8
|
+
- "@iMacTia"
|
9
|
+
- "@olleolleolle"
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
|
-
date:
|
13
|
+
date: 2020-01-01 00:00:00.000000000 Z
|
12
14
|
dependencies:
|
13
15
|
- !ruby/object:Gem::Dependency
|
14
16
|
name: multipart-post
|
@@ -36,8 +38,13 @@ executables: []
|
|
36
38
|
extensions: []
|
37
39
|
extra_rdoc_files: []
|
38
40
|
files:
|
41
|
+
- CHANGELOG.md
|
39
42
|
- LICENSE.md
|
40
43
|
- README.md
|
44
|
+
- Rakefile
|
45
|
+
- UPGRADING.md
|
46
|
+
- examples/client_spec.rb
|
47
|
+
- examples/client_test.rb
|
41
48
|
- lib/faraday.rb
|
42
49
|
- lib/faraday/adapter.rb
|
43
50
|
- lib/faraday/adapter/em_http.rb
|
@@ -59,6 +66,7 @@ files:
|
|
59
66
|
- lib/faraday/encoders/flat_params_encoder.rb
|
60
67
|
- lib/faraday/encoders/nested_params_encoder.rb
|
61
68
|
- lib/faraday/error.rb
|
69
|
+
- lib/faraday/file_part.rb
|
62
70
|
- lib/faraday/logging/formatter.rb
|
63
71
|
- lib/faraday/middleware.rb
|
64
72
|
- lib/faraday/middleware_registry.rb
|
@@ -68,6 +76,7 @@ files:
|
|
68
76
|
- lib/faraday/options/proxy_options.rb
|
69
77
|
- lib/faraday/options/request_options.rb
|
70
78
|
- lib/faraday/options/ssl_options.rb
|
79
|
+
- lib/faraday/param_part.rb
|
71
80
|
- lib/faraday/parameters.rb
|
72
81
|
- lib/faraday/rack_builder.rb
|
73
82
|
- lib/faraday/request.rb
|
@@ -81,20 +90,66 @@ files:
|
|
81
90
|
- lib/faraday/response.rb
|
82
91
|
- lib/faraday/response/logger.rb
|
83
92
|
- lib/faraday/response/raise_error.rb
|
84
|
-
- lib/faraday/upload_io.rb
|
85
93
|
- lib/faraday/utils.rb
|
86
94
|
- lib/faraday/utils/headers.rb
|
87
95
|
- lib/faraday/utils/params_hash.rb
|
88
96
|
- spec/external_adapters/faraday_specs_setup.rb
|
89
|
-
|
97
|
+
- spec/faraday/adapter/em_http_spec.rb
|
98
|
+
- spec/faraday/adapter/em_synchrony_spec.rb
|
99
|
+
- spec/faraday/adapter/excon_spec.rb
|
100
|
+
- spec/faraday/adapter/httpclient_spec.rb
|
101
|
+
- spec/faraday/adapter/net_http_persistent_spec.rb
|
102
|
+
- spec/faraday/adapter/net_http_spec.rb
|
103
|
+
- spec/faraday/adapter/patron_spec.rb
|
104
|
+
- spec/faraday/adapter/rack_spec.rb
|
105
|
+
- spec/faraday/adapter/typhoeus_spec.rb
|
106
|
+
- spec/faraday/adapter_registry_spec.rb
|
107
|
+
- spec/faraday/adapter_spec.rb
|
108
|
+
- spec/faraday/composite_read_io_spec.rb
|
109
|
+
- spec/faraday/connection_spec.rb
|
110
|
+
- spec/faraday/error_spec.rb
|
111
|
+
- spec/faraday/middleware_spec.rb
|
112
|
+
- spec/faraday/options/env_spec.rb
|
113
|
+
- spec/faraday/options/options_spec.rb
|
114
|
+
- spec/faraday/options/proxy_options_spec.rb
|
115
|
+
- spec/faraday/options/request_options_spec.rb
|
116
|
+
- spec/faraday/params_encoders/flat_spec.rb
|
117
|
+
- spec/faraday/params_encoders/nested_spec.rb
|
118
|
+
- spec/faraday/rack_builder_spec.rb
|
119
|
+
- spec/faraday/request/authorization_spec.rb
|
120
|
+
- spec/faraday/request/instrumentation_spec.rb
|
121
|
+
- spec/faraday/request/multipart_spec.rb
|
122
|
+
- spec/faraday/request/retry_spec.rb
|
123
|
+
- spec/faraday/request/url_encoded_spec.rb
|
124
|
+
- spec/faraday/request_spec.rb
|
125
|
+
- spec/faraday/response/logger_spec.rb
|
126
|
+
- spec/faraday/response/middleware_spec.rb
|
127
|
+
- spec/faraday/response/raise_error_spec.rb
|
128
|
+
- spec/faraday/response_spec.rb
|
129
|
+
- spec/faraday/utils/headers_spec.rb
|
130
|
+
- spec/faraday/utils_spec.rb
|
131
|
+
- spec/faraday_spec.rb
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
- spec/support/disabling_stub.rb
|
134
|
+
- spec/support/fake_safe_buffer.rb
|
135
|
+
- spec/support/helper_methods.rb
|
136
|
+
- spec/support/shared_examples/adapter.rb
|
137
|
+
- spec/support/shared_examples/params_encoder.rb
|
138
|
+
- spec/support/shared_examples/request_method.rb
|
139
|
+
- spec/support/streaming_response_checker.rb
|
140
|
+
- spec/support/webmock_rack_app.rb
|
141
|
+
homepage: https://lostisland.github.io/faraday
|
90
142
|
licenses:
|
91
143
|
- MIT
|
92
|
-
metadata:
|
144
|
+
metadata:
|
145
|
+
homepage_uri: https://lostisland.github.io/faraday
|
146
|
+
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v1.0.0
|
147
|
+
source_code_uri: https://github.com/lostisland/faraday
|
148
|
+
bug_tracker_uri: https://github.com/lostisland/faraday/issues
|
93
149
|
post_install_message:
|
94
150
|
rdoc_options: []
|
95
151
|
require_paths:
|
96
152
|
- lib
|
97
|
-
- spec/external_adapters
|
98
153
|
required_ruby_version: !ruby/object:Gem::Requirement
|
99
154
|
requirements:
|
100
155
|
- - ">="
|
@@ -102,12 +157,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
157
|
version: '2.3'
|
103
158
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
159
|
requirements:
|
105
|
-
- - "
|
160
|
+
- - ">="
|
106
161
|
- !ruby/object:Gem::Version
|
107
|
-
version:
|
162
|
+
version: '0'
|
108
163
|
requirements: []
|
109
|
-
|
110
|
-
rubygems_version: 2.7.6
|
164
|
+
rubygems_version: 3.1.2
|
111
165
|
signing_key:
|
112
166
|
specification_version: 4
|
113
167
|
summary: HTTP/REST API client library.
|