sealights-rspec-agent 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/agent/config.rb +6 -6
- data/agent/dependencies/faraday-0.17.0/LICENSE.md +20 -0
- data/agent/dependencies/faraday-0.17.0/README.md +384 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday.rb +248 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter.rb +55 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/em_http.rb +243 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/em_synchrony.rb +106 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/em_synchrony/parallel_manager.rb +66 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/excon.rb +82 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/httpclient.rb +128 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/net_http.rb +152 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/net_http_persistent.rb +68 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/patron.rb +95 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/rack.rb +58 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/sl_em_http_ssl_patch.rb +56 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/test.rb +213 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/adapter/typhoeus.rb +12 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/autoload.rb +84 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/connection.rb +484 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/error.rb +66 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/middleware.rb +37 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/options.rb +373 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/parameters.rb +198 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/rack_builder.rb +237 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/request.rb +114 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/request/authorization.rb +41 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/request/basic_authentication.rb +13 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/request/instrumentation.rb +36 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/request/multipart.rb +68 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/request/retry.rb +212 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/request/token_authentication.rb +15 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/request/url_encoded.rb +36 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/response.rb +97 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/response/logger.rb +80 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/response/raise_error.rb +21 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/upload_io.rb +67 -0
- data/agent/dependencies/faraday-0.17.0/lib/faraday/utils.rb +326 -0
- data/agent/dependencies/jwt-2.2.1/AUTHORS +84 -0
- data/agent/dependencies/jwt-2.2.1/Appraisals +14 -0
- data/agent/dependencies/jwt-2.2.1/CHANGELOG.md +570 -0
- data/agent/dependencies/jwt-2.2.1/Gemfile +3 -0
- data/agent/dependencies/jwt-2.2.1/LICENSE +7 -0
- data/agent/dependencies/jwt-2.2.1/README.md +489 -0
- data/agent/dependencies/jwt-2.2.1/Rakefile +11 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt.rb +30 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/algos/ecdsa.rb +35 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/algos/eddsa.rb +23 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/algos/hmac.rb +33 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/algos/ps.rb +43 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/algos/rsa.rb +19 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/algos/unsupported.rb +16 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/base64.rb +19 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/claims_validator.rb +33 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/decode.rb +100 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/default_options.rb +15 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/encode.rb +68 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/error.rb +20 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/json.rb +18 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/jwk.rb +31 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/jwk/key_finder.rb +57 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/jwk/rsa.rb +47 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/security_utils.rb +57 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/signature.rb +52 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/verify.rb +98 -0
- data/agent/dependencies/jwt-2.2.1/lib/jwt/version.rb +24 -0
- data/agent/dependencies/jwt-2.2.1/ruby-jwt.gemspec +34 -0
- data/agent/dependencies/multipart-post-2.1.1/Gemfile +6 -0
- data/agent/dependencies/multipart-post-2.1.1/History.txt +64 -0
- data/agent/dependencies/multipart-post-2.1.1/LICENSE +21 -0
- data/agent/dependencies/multipart-post-2.1.1/Manifest.txt +9 -0
- data/agent/dependencies/multipart-post-2.1.1/README.md +127 -0
- data/agent/dependencies/multipart-post-2.1.1/Rakefile +6 -0
- data/agent/dependencies/multipart-post-2.1.1/lib/composite_io.rb +108 -0
- data/agent/dependencies/multipart-post-2.1.1/lib/multipart_post.rb +9 -0
- data/agent/dependencies/multipart-post-2.1.1/lib/multipartable.rb +48 -0
- data/agent/dependencies/multipart-post-2.1.1/lib/net/http/post/multipart.rb +28 -0
- data/agent/dependencies/multipart-post-2.1.1/lib/parts.rb +126 -0
- data/agent/dependencies/multipart-post-2.1.1/multipart-post.gemspec +23 -0
- data/agent/http_client.rb +46 -0
- data/agent/listener.rb +1 -1
- data/agent/sealights-rspec-agent.rb +2 -2
- data/agent/tia.rb +5 -1
- metadata +80 -3
- data/agent/rest-client-wrapper.rb +0 -27
@@ -0,0 +1,198 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
|
3
|
+
module SLFaraday
|
4
|
+
module NestedParamsEncoder
|
5
|
+
class << self
|
6
|
+
extend Forwardable
|
7
|
+
def_delegators :'SLFaraday', :escape, :unescape
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.encode(params)
|
11
|
+
return nil if params == nil
|
12
|
+
|
13
|
+
if !params.is_a?(Array)
|
14
|
+
if !params.respond_to?(:to_hash)
|
15
|
+
raise TypeError,
|
16
|
+
"Can't convert #{params.class} into Hash."
|
17
|
+
end
|
18
|
+
params = params.to_hash
|
19
|
+
params = params.map do |key, value|
|
20
|
+
key = key.to_s if key.kind_of?(Symbol)
|
21
|
+
[key, value]
|
22
|
+
end
|
23
|
+
# Useful default for OAuth and caching.
|
24
|
+
# Only to be used for non-Array inputs. Arrays should preserve order.
|
25
|
+
params.sort!
|
26
|
+
end
|
27
|
+
|
28
|
+
# Helper lambda
|
29
|
+
to_query = lambda do |parent, value|
|
30
|
+
if value.is_a?(Hash)
|
31
|
+
value = value.map do |key, val|
|
32
|
+
key = escape(key)
|
33
|
+
[key, val]
|
34
|
+
end
|
35
|
+
value.sort!
|
36
|
+
buffer = ""
|
37
|
+
value.each do |key, val|
|
38
|
+
new_parent = "#{parent}%5B#{key}%5D"
|
39
|
+
buffer << "#{to_query.call(new_parent, val)}&"
|
40
|
+
end
|
41
|
+
return buffer.chop
|
42
|
+
elsif value.is_a?(Array)
|
43
|
+
new_parent = "#{parent}%5B%5D"
|
44
|
+
return new_parent if value.empty?
|
45
|
+
buffer = ""
|
46
|
+
value.each_with_index do |val, i|
|
47
|
+
buffer << "#{to_query.call(new_parent, val)}&"
|
48
|
+
end
|
49
|
+
return buffer.chop
|
50
|
+
elsif value.nil?
|
51
|
+
return parent
|
52
|
+
else
|
53
|
+
encoded_value = escape(value)
|
54
|
+
return "#{parent}=#{encoded_value}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# The params have form [['key1', 'value1'], ['key2', 'value2']].
|
59
|
+
buffer = ''
|
60
|
+
params.each do |parent, value|
|
61
|
+
encoded_parent = escape(parent)
|
62
|
+
buffer << "#{to_query.call(encoded_parent, value)}&"
|
63
|
+
end
|
64
|
+
return buffer.chop
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.decode(query)
|
68
|
+
return nil if query == nil
|
69
|
+
|
70
|
+
params = {}
|
71
|
+
query.split("&").each do |pair|
|
72
|
+
next if pair.empty?
|
73
|
+
key, value = pair.split("=", 2)
|
74
|
+
key = unescape(key)
|
75
|
+
value = unescape(value.gsub(/\+/, ' ')) if value
|
76
|
+
|
77
|
+
subkeys = key.scan(/[^\[\]]+(?:\]?\[\])?/)
|
78
|
+
context = params
|
79
|
+
subkeys.each_with_index do |subkey, i|
|
80
|
+
is_array = subkey =~ /[\[\]]+\Z/
|
81
|
+
subkey = $` if is_array
|
82
|
+
last_subkey = i == subkeys.length - 1
|
83
|
+
|
84
|
+
if !last_subkey || is_array
|
85
|
+
value_type = is_array ? Array : Hash
|
86
|
+
if context[subkey] && !context[subkey].is_a?(value_type)
|
87
|
+
raise TypeError, "expected %s (got %s) for param `%s'" % [
|
88
|
+
value_type.name,
|
89
|
+
context[subkey].class.name,
|
90
|
+
subkey
|
91
|
+
]
|
92
|
+
end
|
93
|
+
context = (context[subkey] ||= value_type.new)
|
94
|
+
end
|
95
|
+
|
96
|
+
if context.is_a?(Array) && !is_array
|
97
|
+
if !context.last.is_a?(Hash) || context.last.has_key?(subkey)
|
98
|
+
context << {}
|
99
|
+
end
|
100
|
+
context = context.last
|
101
|
+
end
|
102
|
+
|
103
|
+
if last_subkey
|
104
|
+
if is_array
|
105
|
+
context << value
|
106
|
+
else
|
107
|
+
context[subkey] = value
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
dehash(params, 0)
|
114
|
+
end
|
115
|
+
|
116
|
+
# Internal: convert a nested hash with purely numeric keys into an array.
|
117
|
+
# FIXME: this is not compatible with Rack::Utils.parse_nested_query
|
118
|
+
def self.dehash(hash, depth)
|
119
|
+
hash.each do |key, value|
|
120
|
+
hash[key] = dehash(value, depth + 1) if value.kind_of?(Hash)
|
121
|
+
end
|
122
|
+
|
123
|
+
if depth > 0 && !hash.empty? && hash.keys.all? { |k| k =~ /^\d+$/ }
|
124
|
+
hash.keys.sort.inject([]) { |all, key| all << hash[key] }
|
125
|
+
else
|
126
|
+
hash
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
module FlatParamsEncoder
|
132
|
+
class << self
|
133
|
+
extend Forwardable
|
134
|
+
def_delegators :'SLFaraday', :escape, :unescape
|
135
|
+
end
|
136
|
+
|
137
|
+
def self.encode(params)
|
138
|
+
return nil if params == nil
|
139
|
+
|
140
|
+
if !params.is_a?(Array)
|
141
|
+
if !params.respond_to?(:to_hash)
|
142
|
+
raise TypeError,
|
143
|
+
"Can't convert #{params.class} into Hash."
|
144
|
+
end
|
145
|
+
params = params.to_hash
|
146
|
+
params = params.map do |key, value|
|
147
|
+
key = key.to_s if key.kind_of?(Symbol)
|
148
|
+
[key, value]
|
149
|
+
end
|
150
|
+
# Useful default for OAuth and caching.
|
151
|
+
# Only to be used for non-Array inputs. Arrays should preserve order.
|
152
|
+
params.sort!
|
153
|
+
end
|
154
|
+
|
155
|
+
# The params have form [['key1', 'value1'], ['key2', 'value2']].
|
156
|
+
buffer = ''
|
157
|
+
params.each do |key, value|
|
158
|
+
encoded_key = escape(key)
|
159
|
+
value = value.to_s if value == true || value == false
|
160
|
+
if value == nil
|
161
|
+
buffer << "#{encoded_key}&"
|
162
|
+
elsif value.kind_of?(Array)
|
163
|
+
value.each do |sub_value|
|
164
|
+
encoded_value = escape(sub_value)
|
165
|
+
buffer << "#{encoded_key}=#{encoded_value}&"
|
166
|
+
end
|
167
|
+
else
|
168
|
+
encoded_value = escape(value)
|
169
|
+
buffer << "#{encoded_key}=#{encoded_value}&"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
return buffer.chop
|
173
|
+
end
|
174
|
+
|
175
|
+
def self.decode(query)
|
176
|
+
empty_accumulator = {}
|
177
|
+
return nil if query == nil
|
178
|
+
split_query = (query.split('&').map do |pair|
|
179
|
+
pair.split('=', 2) if pair && !pair.empty?
|
180
|
+
end).compact
|
181
|
+
return split_query.inject(empty_accumulator.dup) do |accu, pair|
|
182
|
+
pair[0] = unescape(pair[0])
|
183
|
+
pair[1] = true if pair[1].nil?
|
184
|
+
if pair[1].respond_to?(:to_str)
|
185
|
+
pair[1] = unescape(pair[1].to_str.gsub(/\+/, " "))
|
186
|
+
end
|
187
|
+
if accu[pair[0]].kind_of?(Array)
|
188
|
+
accu[pair[0]] << pair[1]
|
189
|
+
elsif accu[pair[0]]
|
190
|
+
accu[pair[0]] = [accu[pair[0]], pair[1]]
|
191
|
+
else
|
192
|
+
accu[pair[0]] = pair[1]
|
193
|
+
end
|
194
|
+
accu
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
@@ -0,0 +1,237 @@
|
|
1
|
+
module SLFaraday
|
2
|
+
# A Builder that processes requests into responses by passing through an inner
|
3
|
+
# middleware stack (heavily inspired by Rack).
|
4
|
+
#
|
5
|
+
# Faraday::Connection.new(:url => 'http://sushi.com') do |builder|
|
6
|
+
# builder.request :url_encoded # Faraday::Request::UrlEncoded
|
7
|
+
# builder.adapter :net_http # Faraday::Adapter::NetHttp
|
8
|
+
# end
|
9
|
+
class RackBuilder
|
10
|
+
attr_accessor :handlers
|
11
|
+
|
12
|
+
# Error raised when trying to modify the stack after calling `lock!`
|
13
|
+
class StackLocked < RuntimeError; end
|
14
|
+
|
15
|
+
# borrowed from ActiveSupport::Dependencies::Reference &
|
16
|
+
# ActionDispatch::MiddlewareStack::Middleware
|
17
|
+
class Handler
|
18
|
+
@@constants_mutex = Mutex.new
|
19
|
+
@@constants = Hash.new { |h, k|
|
20
|
+
value = k.respond_to?(:constantize) ? k.constantize : Object.const_get(k)
|
21
|
+
@@constants_mutex.synchronize { h[k] = value }
|
22
|
+
}
|
23
|
+
|
24
|
+
attr_reader :name
|
25
|
+
|
26
|
+
def initialize(klass, *args, &block)
|
27
|
+
@name = klass.to_s
|
28
|
+
if klass.respond_to?(:name)
|
29
|
+
@@constants_mutex.synchronize { @@constants[@name] = klass }
|
30
|
+
end
|
31
|
+
@args, @block = args, block
|
32
|
+
end
|
33
|
+
|
34
|
+
def klass() @@constants[@name] end
|
35
|
+
def inspect() @name end
|
36
|
+
|
37
|
+
def ==(other)
|
38
|
+
if other.is_a? Handler
|
39
|
+
self.name == other.name
|
40
|
+
elsif other.respond_to? :name
|
41
|
+
klass == other
|
42
|
+
else
|
43
|
+
@name == other.to_s
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def build(app)
|
48
|
+
klass.new(app, *@args, &@block)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def initialize(handlers = [])
|
53
|
+
@handlers = handlers
|
54
|
+
if block_given?
|
55
|
+
build(&Proc.new)
|
56
|
+
elsif @handlers.empty?
|
57
|
+
# default stack, if nothing else is configured
|
58
|
+
self.request :url_encoded
|
59
|
+
self.adapter SLFaraday.default_adapter
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def build(options = {})
|
64
|
+
raise_if_locked
|
65
|
+
@handlers.clear unless options[:keep]
|
66
|
+
yield(self) if block_given?
|
67
|
+
end
|
68
|
+
|
69
|
+
def [](idx)
|
70
|
+
@handlers[idx]
|
71
|
+
end
|
72
|
+
|
73
|
+
# Locks the middleware stack to ensure no further modifications are possible.
|
74
|
+
def lock!
|
75
|
+
@handlers.freeze
|
76
|
+
end
|
77
|
+
|
78
|
+
def locked?
|
79
|
+
@handlers.frozen?
|
80
|
+
end
|
81
|
+
|
82
|
+
def use(klass, *args, &block)
|
83
|
+
if klass.is_a? Symbol
|
84
|
+
use_symbol(SLFaraday::Middleware, klass, *args, &block)
|
85
|
+
else
|
86
|
+
raise_if_locked
|
87
|
+
warn_middleware_after_adapter if adapter_set?
|
88
|
+
@handlers << self.class::Handler.new(klass, *args, &block)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def request(key, *args, &block)
|
93
|
+
use_symbol(SLFaraday::Request, key, *args, &block)
|
94
|
+
end
|
95
|
+
|
96
|
+
def response(key, *args, &block)
|
97
|
+
use_symbol(SLFaraday::Response, key, *args, &block)
|
98
|
+
end
|
99
|
+
|
100
|
+
def adapter(key, *args, &block)
|
101
|
+
use_symbol(SLFaraday::Adapter, key, *args, &block)
|
102
|
+
end
|
103
|
+
|
104
|
+
## methods to push onto the various positions in the stack:
|
105
|
+
|
106
|
+
def insert(index, *args, &block)
|
107
|
+
raise_if_locked
|
108
|
+
index = assert_index(index)
|
109
|
+
warn_middleware_after_adapter if inserting_after_adapter?(index)
|
110
|
+
handler = self.class::Handler.new(*args, &block)
|
111
|
+
@handlers.insert(index, handler)
|
112
|
+
end
|
113
|
+
|
114
|
+
alias_method :insert_before, :insert
|
115
|
+
|
116
|
+
def insert_after(index, *args, &block)
|
117
|
+
index = assert_index(index)
|
118
|
+
insert(index + 1, *args, &block)
|
119
|
+
end
|
120
|
+
|
121
|
+
def swap(index, *args, &block)
|
122
|
+
raise_if_locked
|
123
|
+
index = assert_index(index)
|
124
|
+
@handlers.delete_at(index)
|
125
|
+
insert(index, *args, &block)
|
126
|
+
end
|
127
|
+
|
128
|
+
def delete(handler)
|
129
|
+
raise_if_locked
|
130
|
+
@handlers.delete(handler)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Processes a Request into a Response by passing it through this Builder's
|
134
|
+
# middleware stack.
|
135
|
+
#
|
136
|
+
# connection - Faraday::Connection
|
137
|
+
# request - Faraday::Request
|
138
|
+
#
|
139
|
+
# Returns a Faraday::Response.
|
140
|
+
def build_response(connection, request)
|
141
|
+
warn 'WARNING: No adapter was configured for this request' unless adapter_set?
|
142
|
+
|
143
|
+
app.call(build_env(connection, request))
|
144
|
+
end
|
145
|
+
|
146
|
+
# The "rack app" wrapped in middleware. All requests are sent here.
|
147
|
+
#
|
148
|
+
# The builder is responsible for creating the app object. After this,
|
149
|
+
# the builder gets locked to ensure no further modifications are made
|
150
|
+
# to the middleware stack.
|
151
|
+
#
|
152
|
+
# Returns an object that responds to `call` and returns a Response.
|
153
|
+
def app
|
154
|
+
@app ||= begin
|
155
|
+
lock!
|
156
|
+
to_app(lambda { |env|
|
157
|
+
response = Response.new
|
158
|
+
env.response = response
|
159
|
+
response.finish(env) unless env.parallel?
|
160
|
+
response
|
161
|
+
})
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def to_app(inner_app)
|
166
|
+
# last added handler is the deepest and thus closest to the inner app
|
167
|
+
@handlers.reverse.inject(inner_app) { |app, handler| handler.build(app) }
|
168
|
+
end
|
169
|
+
|
170
|
+
def ==(other)
|
171
|
+
other.is_a?(self.class) && @handlers == other.handlers
|
172
|
+
end
|
173
|
+
|
174
|
+
def dup
|
175
|
+
self.class.new(@handlers.dup)
|
176
|
+
end
|
177
|
+
|
178
|
+
# ENV Keys
|
179
|
+
# :method - a symbolized request method (:get, :post)
|
180
|
+
# :body - the request body that will eventually be converted to a string.
|
181
|
+
# :url - URI instance for the current request.
|
182
|
+
# :status - HTTP response status code
|
183
|
+
# :request_headers - hash of HTTP Headers to be sent to the server
|
184
|
+
# :response_headers - Hash of HTTP headers from the server
|
185
|
+
# :parallel_manager - sent if the connection is in parallel mode
|
186
|
+
# :request - Hash of options for configuring the request.
|
187
|
+
# :timeout - open/read timeout Integer in seconds
|
188
|
+
# :open_timeout - read timeout Integer in seconds
|
189
|
+
# :proxy - Hash of proxy options
|
190
|
+
# :uri - Proxy Server URI
|
191
|
+
# :user - Proxy server username
|
192
|
+
# :password - Proxy server password
|
193
|
+
# :ssl - Hash of options for configuring SSL requests.
|
194
|
+
def build_env(connection, request)
|
195
|
+
Env.new(request.method, request.body,
|
196
|
+
connection.build_exclusive_url(request.path, request.params, request.options.params_encoder),
|
197
|
+
request.options, request.headers, connection.ssl,
|
198
|
+
connection.parallel_manager)
|
199
|
+
end
|
200
|
+
|
201
|
+
private
|
202
|
+
|
203
|
+
def raise_if_locked
|
204
|
+
raise StackLocked, "can't modify middleware stack after making a request" if locked?
|
205
|
+
end
|
206
|
+
|
207
|
+
def warn_middleware_after_adapter
|
208
|
+
warn "WARNING: Unexpected middleware set after the adapter. " \
|
209
|
+
"This won't be supported from Faraday 1.0."
|
210
|
+
end
|
211
|
+
|
212
|
+
def adapter_set?
|
213
|
+
@handlers.any? { |handler| is_adapter?(handler) }
|
214
|
+
end
|
215
|
+
|
216
|
+
def inserting_after_adapter?(index)
|
217
|
+
adapter_index = @handlers.find_index { |handler| is_adapter?(handler) }
|
218
|
+
return false if adapter_index.nil?
|
219
|
+
|
220
|
+
index > adapter_index
|
221
|
+
end
|
222
|
+
|
223
|
+
def is_adapter?(handler)
|
224
|
+
handler.klass.ancestors.include? SLFaraday::Adapter
|
225
|
+
end
|
226
|
+
|
227
|
+
def use_symbol(mod, key, *args, &block)
|
228
|
+
use(mod.lookup_middleware(key), *args, &block)
|
229
|
+
end
|
230
|
+
|
231
|
+
def assert_index(index)
|
232
|
+
idx = index.is_a?(Integer) ? index : @handlers.index(index)
|
233
|
+
raise "No such handler: #{index.inspect}" unless idx
|
234
|
+
idx
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module SLFaraday
|
2
|
+
# Used to setup urls, params, headers, and the request body in a sane manner.
|
3
|
+
#
|
4
|
+
# @connection.post do |req|
|
5
|
+
# req.url 'http://localhost', 'a' => '1' # 'http://localhost?a=1'
|
6
|
+
# req.headers['b'] = '2' # Header
|
7
|
+
# req.params['c'] = '3' # GET Param
|
8
|
+
# req['b'] = '2' # also Header
|
9
|
+
# req.body = 'abc'
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
class Request < Struct.new(:method, :path, :params, :headers, :body, :options)
|
13
|
+
extend MiddlewareRegistry
|
14
|
+
|
15
|
+
register_middleware File.expand_path('../request', __FILE__),
|
16
|
+
:url_encoded => [:UrlEncoded, 'url_encoded'],
|
17
|
+
:multipart => [:Multipart, 'multipart'],
|
18
|
+
:retry => [:Retry, 'retry'],
|
19
|
+
:authorization => [:Authorization, 'authorization'],
|
20
|
+
:basic_auth => [:BasicAuthentication, 'basic_authentication'],
|
21
|
+
:token_auth => [:TokenAuthentication, 'token_authentication'],
|
22
|
+
:instrumentation => [:Instrumentation, 'instrumentation']
|
23
|
+
|
24
|
+
def self.create(request_method)
|
25
|
+
new(request_method).tap do |request|
|
26
|
+
yield(request) if block_given?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Public: Replace params, preserving the existing hash type
|
31
|
+
def params=(hash)
|
32
|
+
if params
|
33
|
+
params.replace hash
|
34
|
+
else
|
35
|
+
super
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Public: Replace request headers, preserving the existing hash type
|
40
|
+
def headers=(hash)
|
41
|
+
if headers
|
42
|
+
headers.replace hash
|
43
|
+
else
|
44
|
+
super
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def url(path, params = nil)
|
49
|
+
if path.respond_to? :query
|
50
|
+
if query = path.query
|
51
|
+
path = path.dup
|
52
|
+
path.query = nil
|
53
|
+
end
|
54
|
+
else
|
55
|
+
anchor_index = path.index('#')
|
56
|
+
path = path.slice(0, anchor_index) unless anchor_index.nil?
|
57
|
+
path, query = path.split('?', 2)
|
58
|
+
end
|
59
|
+
self.path = path
|
60
|
+
self.params.merge_query query, options.params_encoder
|
61
|
+
self.params.update(params) if params
|
62
|
+
end
|
63
|
+
|
64
|
+
def [](key)
|
65
|
+
headers[key]
|
66
|
+
end
|
67
|
+
|
68
|
+
def []=(key, value)
|
69
|
+
headers[key] = value
|
70
|
+
end
|
71
|
+
|
72
|
+
def marshal_dump
|
73
|
+
{
|
74
|
+
:method => method,
|
75
|
+
:body => body,
|
76
|
+
:headers => headers,
|
77
|
+
:path => path,
|
78
|
+
:params => params,
|
79
|
+
:options => options
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
def marshal_load(serialised)
|
84
|
+
self.method = serialised[:method]
|
85
|
+
self.body = serialised[:body]
|
86
|
+
self.headers = serialised[:headers]
|
87
|
+
self.path = serialised[:path]
|
88
|
+
self.params = serialised[:params]
|
89
|
+
self.options = serialised[:options]
|
90
|
+
end
|
91
|
+
|
92
|
+
# ENV Keys
|
93
|
+
# :method - a symbolized request method (:get, :post)
|
94
|
+
# :body - the request body that will eventually be converted to a string.
|
95
|
+
# :url - URI instance for the current request.
|
96
|
+
# :status - HTTP response status code
|
97
|
+
# :request_headers - hash of HTTP Headers to be sent to the server
|
98
|
+
# :response_headers - Hash of HTTP headers from the server
|
99
|
+
# :parallel_manager - sent if the connection is in parallel mode
|
100
|
+
# :request - Hash of options for configuring the request.
|
101
|
+
# :timeout - open/read timeout Integer in seconds
|
102
|
+
# :open_timeout - read timeout Integer in seconds
|
103
|
+
# :proxy - Hash of proxy options
|
104
|
+
# :uri - Proxy Server URI
|
105
|
+
# :user - Proxy server username
|
106
|
+
# :password - Proxy server password
|
107
|
+
# :ssl - Hash of options for configuring SSL requests.
|
108
|
+
def to_env(connection)
|
109
|
+
Env.new(method, body, connection.build_exclusive_url(path, params),
|
110
|
+
options, headers, connection.ssl, connection.parallel_manager)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|