workato-connector-sdk 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,44 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require 'securerandom'
5
+
6
+ module Workato
7
+ module Connector
8
+ module Sdk
9
+ module Dsl
10
+ module ExecutionContext
11
+ extend T::Sig
12
+ extend T::Helpers
13
+ extend ActiveSupport::Concern
14
+
15
+ included do
16
+ T.bind(self, Class)
17
+
18
+ # encrypted safe recipe_id
19
+ class_attribute :recipe_id, instance_predicate: false, default: SecureRandom.hex(32)
20
+ end
21
+
22
+ sig { returns(T::Hash[Symbol, T.untyped]) }
23
+ def execution_context
24
+ @execution_context ||= {
25
+ recipe_id: recipe_id
26
+ }.compact
27
+ end
28
+
29
+ # mock unencrypted recipe_id for testing only
30
+ def recipe_id!
31
+ recipe_id.reverse
32
+ end
33
+
34
+ module ClassMethods
35
+ # mock unencrypted recipe_id for testing only
36
+ def recipe_id!
37
+ T.unsafe(self).recipe_id.reverse
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -2,6 +2,9 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'jwt'
5
+ require_relative './csv'
6
+
7
+ using Workato::Extension::HashWithIndifferentAccess
5
8
 
6
9
  module Workato
7
10
  module Connector
@@ -74,7 +77,7 @@ module Workato
74
77
  raise "A RSA key of size #{JWT_RSA_KEY_MIN_LENGTH} bits or larger MUST be used with JWT."
75
78
  end
76
79
 
77
- header_fields = header_fields.present? ? header_fields.with_indifferent_access.except(:typ, :alg) : {}
80
+ header_fields = HashWithIndifferentAccess.wrap(header_fields).except(:typ, :alg)
78
81
  ::JWT.encode(payload, rsa_private, algorithm, header_fields)
79
82
  end
80
83
 
@@ -152,6 +155,10 @@ module Workato
152
155
  def pbkdf2_hmac_sha1(string, salt, iterations = 1000, key_len = 16)
153
156
  Extension::Binary.new(::OpenSSL::PKCS5.pbkdf2_hmac_sha1(string, salt, iterations, key_len))
154
157
  end
158
+
159
+ def csv
160
+ Csv
161
+ end
155
162
  end
156
163
  end
157
164
  end
@@ -12,6 +12,7 @@ require_relative './dsl/workato_code_lib'
12
12
  require_relative './dsl/workato_schema'
13
13
  require_relative './dsl/time'
14
14
  require_relative './dsl/aws'
15
+ require_relative './dsl/execution_context'
15
16
 
16
17
  module Workato
17
18
  module Connector
@@ -30,6 +30,17 @@ module Workato
30
30
 
31
31
  CustomRequestError = Class.new(StandardError)
32
32
 
33
+ InvalidMultiAuthDefinition = Class.new(InvalidDefinitionError)
34
+
35
+ class UnresolvedMultiAuthOptionError < InvalidMultiAuthDefinition
36
+ attr_reader :name
37
+
38
+ def initialize(name)
39
+ super("Cannot find multi-auth definition for '#{name}'")
40
+ @name = name
41
+ end
42
+ end
43
+
33
44
  RuntimeError = Class.new(StandardError)
34
45
 
35
46
  class UnresolvedObjectDefinitionError < StandardError
@@ -4,6 +4,8 @@
4
4
  require 'csv'
5
5
  require 'singleton'
6
6
 
7
+ using Workato::Extension::HashWithIndifferentAccess
8
+
7
9
  module Workato
8
10
  module Connector
9
11
  module Sdk
@@ -40,7 +42,7 @@ module Workato
40
42
  @table_by_id ||= {}
41
43
  @table_by_name ||= {}
42
44
  data.each do |name, table|
43
- table = table.with_indifferent_access
45
+ table = HashWithIndifferentAccess.wrap(table)
44
46
  rows = table['rows'].freeze
45
47
  @table_by_id[table['id'].to_i] = rows
46
48
  @table_by_name[name] = rows
@@ -5,6 +5,8 @@ require_relative './dsl'
5
5
  require_relative './block_invocation_refinements'
6
6
  require_relative './schema'
7
7
 
8
+ using Workato::Extension::HashWithIndifferentAccess
9
+
8
10
  module Workato
9
11
  module Connector
10
12
  module Sdk
@@ -45,6 +47,7 @@ module Workato
45
47
  include Dsl::HTTP
46
48
  include Dsl::Call
47
49
  include Dsl::Error
50
+ include Dsl::ExecutionContext
48
51
 
49
52
  using BlockInvocationRefinements
50
53
 
@@ -57,8 +60,8 @@ module Workato
57
60
  ).void
58
61
  end
59
62
  def initialize(operation: {}, methods: {}, connection: Connection.new, object_definitions: nil)
60
- @operation = T.let(operation.with_indifferent_access, HashWithIndifferentAccess)
61
- @_methods = T.let(methods.with_indifferent_access, HashWithIndifferentAccess)
63
+ @operation = T.let(HashWithIndifferentAccess.wrap(operation), HashWithIndifferentAccess)
64
+ @_methods = T.let(HashWithIndifferentAccess.wrap(methods), HashWithIndifferentAccess)
62
65
  @connection = T.let(connection, Connection)
63
66
  @object_definitions = T.let(object_definitions, T.nilable(ObjectDefinitions))
64
67
  end
@@ -80,13 +83,14 @@ module Workato
80
83
  connection.merge_settings!(settings) if settings
81
84
  request_or_result = T.unsafe(self).instance_exec(
82
85
  connection.settings,
83
- input.with_indifferent_access,
84
- Array.wrap(extended_input_schema).map(&:with_indifferent_access),
85
- Array.wrap(extended_output_schema).map(&:with_indifferent_access),
86
- continue.with_indifferent_access,
86
+ HashWithIndifferentAccess.wrap(input),
87
+ Array.wrap(extended_input_schema).map { |i| HashWithIndifferentAccess.wrap(i) },
88
+ Array.wrap(extended_output_schema).map { |i| HashWithIndifferentAccess.wrap(i) },
89
+ HashWithIndifferentAccess.wrap(continue),
87
90
  &block
88
91
  )
89
- resolve_request(request_or_result)
92
+ result = resolve_request(request_or_result)
93
+ try_convert_to_hash_with_indifferent_access(result)
90
94
  end
91
95
 
92
96
  sig do
@@ -225,7 +229,7 @@ module Workato
225
229
  end
226
230
  end
227
231
  when ::Hash
228
- request_or_result.inject(request_or_result.with_indifferent_access) do |acc, (key, value)|
232
+ request_or_result.inject(request_or_result) do |acc, (key, value)|
229
233
  response_value = resolve_request(value)
230
234
  if response_value.equal?(value)
231
235
  acc
@@ -238,6 +242,18 @@ module Workato
238
242
  end
239
243
  end
240
244
 
245
+ sig { params(value: T.untyped).returns(T.untyped) }
246
+ def try_convert_to_hash_with_indifferent_access(value)
247
+ case value
248
+ when ::Hash
249
+ HashWithIndifferentAccess.wrap(value)
250
+ when ::Array
251
+ value.map! { |i| try_convert_to_hash_with_indifferent_access(i) }
252
+ else
253
+ value
254
+ end
255
+ end
256
+
241
257
  sig { returns(ObjectDefinitions) }
242
258
  def object_definitions
243
259
  T.must(@object_definitions)
@@ -8,8 +8,11 @@ require 'gyoku'
8
8
  require 'net/http'
9
9
  require 'net/http/digest_auth'
10
10
 
11
+ require 'workato/utilities/encoding'
12
+ require 'workato/utilities/xml'
11
13
  require_relative './block_invocation_refinements'
12
- require_relative './../../utilities/encoding'
14
+
15
+ using Workato::Extension::HashWithIndifferentAccess
13
16
 
14
17
  module Workato
15
18
  module Connector
@@ -31,6 +34,7 @@ module Workato
31
34
  @render_request = ->(payload) { payload }
32
35
  @parse_response = ->(payload) { payload }
33
36
  @after_response = ->(_response_code, parsed_response, _response_headers) { parsed_response }
37
+ @callstack_before_request = Array.wrap(Kernel.caller)
34
38
  end
35
39
 
36
40
  def method_missing(*args, &block)
@@ -38,36 +42,24 @@ module Workato
38
42
  end
39
43
 
40
44
  def execute!
41
- __getobj__ || __setobj__(
42
- authorized do
43
- begin
44
- request = build_request
45
- response = execute(request)
46
- rescue RestClient::Unauthorized => e
47
- Kernel.raise e unless @digest_auth
48
-
49
- @digest_auth = false
50
- headers('Authorization' => Net::HTTP::DigestAuth.new.auth_header(
51
- URI.parse(build_url),
52
- e.response.headers[:www_authenticate],
53
- method.to_s.upcase
54
- ))
55
- request = build_request
56
- response = execute(request)
57
- end
58
- detect_error!(response.body)
59
- parsed_response = @parse_response.call(response)
60
- detect_error!(parsed_response)
61
- apply_after_response(response.code, parsed_response, response.headers)
62
- end
63
- )
45
+ __getobj__ || __setobj__(response)
64
46
  rescue RestClient::Exception => e
65
47
  if after_error_response_matches?(e)
66
48
  return apply_after_error_response(e)
67
49
  end
68
50
 
69
- Kernel.raise RequestError.new(response: e.response, message: e.message, method: current_verb,
70
- code: e.http_code)
51
+ Kernel.raise RequestError.new(
52
+ response: e.response,
53
+ message: e.message,
54
+ method: current_verb,
55
+ code: e.http_code
56
+ )
57
+ rescue StandardError => e
58
+ error_backtrace = Array.wrap(e.backtrace)
59
+ first_call_after_request_idx = error_backtrace.rindex { |s| s.start_with?(__FILE__) }
60
+ error_backtrace_after_request = error_backtrace[0..first_call_after_request_idx]
61
+ e.set_backtrace(error_backtrace_after_request + @callstack_before_request)
62
+ Kernel.raise e
71
63
  end
72
64
 
73
65
  def headers(headers)
@@ -178,7 +170,7 @@ module Workato
178
170
  def response_format_xml(strip_response_namespaces: false)
179
171
  @accept_header = :xml
180
172
  @parse_response = lambda_with_error_wrap(XMLResponseFormatError) do |payload|
181
- Xml.parse_xml_to_hash(payload, strip_namespaces: strip_response_namespaces)
173
+ Workato::Utilities::Xml.parse_xml_to_hash(payload, strip_namespaces: strip_response_namespaces)
182
174
  end
183
175
  self
184
176
  end
@@ -266,7 +258,31 @@ module Workato
266
258
 
267
259
  attr_reader :method
268
260
 
269
- def execute(request)
261
+ def response
262
+ authorized do
263
+ begin
264
+ request = RestClientRequest.new(rest_request_params)
265
+ response = execute_request(request)
266
+ rescue RestClient::Unauthorized => e
267
+ Kernel.raise e unless @digest_auth
268
+
269
+ @digest_auth = false
270
+ headers('Authorization' => Net::HTTP::DigestAuth.new.auth_header(
271
+ URI.parse(build_url),
272
+ e.response.headers[:www_authenticate],
273
+ method.to_s.upcase
274
+ ))
275
+ request = RestClientRequest.new(rest_request_params)
276
+ response = execute_request(request)
277
+ end
278
+ detect_error!(response.body)
279
+ parsed_response = @parse_response.call(response)
280
+ detect_error!(parsed_response)
281
+ apply_after_response(response.code, parsed_response, response.headers)
282
+ end
283
+ end
284
+
285
+ def execute_request(request)
270
286
  if @follow_redirection.nil?
271
287
  request.execute
272
288
  else
@@ -285,25 +301,22 @@ module Workato
285
301
  end
286
302
  end
287
303
 
288
- def build_request
289
- RestClient::Request.new(
290
- {
291
- method: method,
292
- url: build_url,
293
- headers: build_headers,
294
- payload: @render_request.call(@payload)
295
- }.tap do |request_hash|
296
- if @ssl_client_cert.present? && @ssl_client_key.present?
297
- request_hash[:ssl_client_cert] = @ssl_client_cert
298
- request_hash[:ssl_client_key] = @ssl_client_key
304
+ def rest_request_params
305
+ {
306
+ method: method,
307
+ url: build_url,
308
+ headers: build_headers,
309
+ payload: @render_request.call(@payload),
310
+ case_sensitive_headers: @case_sensitive_headers.transform_keys(&:to_s)
311
+ }.tap do |request_hash|
312
+ if @ssl_client_cert.present? && @ssl_client_key.present?
313
+ request_hash[:ssl_client_cert] = @ssl_client_cert
314
+ request_hash[:ssl_client_key] = @ssl_client_key
315
+ if @ssl_client_intermediate_certs.present?
316
+ request_hash[:ssl_extra_chain_cert] = @ssl_client_intermediate_certs
299
317
  end
300
- request_hash[:ssl_cert_store] = @ssl_cert_store if @ssl_cert_store
301
- end
302
- ).tap do |request|
303
- request.case_sensitive_headers = @case_sensitive_headers.transform_keys(&:to_s)
304
- if @ssl_client_intermediate_certs.present? && @ssl_client_cert.present? && @ssl_client_key.present?
305
- request.extra_chain_cert = @ssl_client_intermediate_certs
306
318
  end
319
+ request_hash[:ssl_cert_store] = @ssl_cert_store if @ssl_cert_store
307
320
  end
308
321
  end
309
322
 
@@ -373,7 +386,7 @@ module Workato
373
386
  within_action_context(
374
387
  exception.http_code,
375
388
  exception.http_body,
376
- exception.http_headers&.with_indifferent_access || {},
389
+ HashWithIndifferentAccess.wrap(exception.http_headers),
377
390
  exception.message,
378
391
  &@after_error_response
379
392
  )
@@ -404,7 +417,7 @@ module Workato
404
417
  first = true
405
418
  begin
406
419
  settings = connection.settings
407
- if /oauth2/i =~ connection.authorization.type
420
+ if connection.authorization.oauth2?
408
421
  instance_exec(settings, settings[:access_token], @auth_type, &apply)
409
422
  else
410
423
  instance_exec(settings, @auth_type, &apply)
@@ -461,6 +474,35 @@ module Workato
461
474
  attr_reader :content_type
462
475
  attr_reader :original_filename
463
476
  end
477
+
478
+ class RestClientRequest < ::RestClient::Request
479
+ def initialize(args)
480
+ super
481
+ @ssl_opts[:extra_chain_cert] = args[:ssl_extra_chain_cert] if args.key?(:ssl_extra_chain_cert)
482
+ @case_sensitive_headers = args[:case_sensitive_headers]
483
+ @before_execution_proc = proc do |net_http_request, _args|
484
+ net_http_request.case_sensitive_headers = args[:case_sensitive_headers]
485
+ end
486
+ end
487
+
488
+ def ssl_extra_chain_cert
489
+ @ssl_opts[:extra_chain_cert]
490
+ end
491
+
492
+ def processed_headers
493
+ return @processed_headers if @case_sensitive_headers.blank?
494
+ return @case_sensitive_headers if @processed_headers.blank?
495
+
496
+ @processed_headers.merge(@case_sensitive_headers)
497
+ end
498
+
499
+ def net_http_object(hostname, port)
500
+ net = super(hostname, port)
501
+ net.extra_chain_cert = ssl_extra_chain_cert if ssl_extra_chain_cert
502
+ net
503
+ end
504
+ end
505
+ private_constant :RestClientRequest
464
506
  end
465
507
  end
466
508
  end
@@ -1,20 +1,22 @@
1
1
  # typed: false
2
2
  # frozen_string_literal: true
3
3
 
4
+ using Workato::Extension::HashWithIndifferentAccess
5
+
4
6
  module Workato
5
7
  module Connector
6
8
  module Sdk
7
9
  class Schema < SimpleDelegator
8
10
  def initialize(schema: [])
9
- super(Fields.new(::Array.wrap(schema).map(&:with_indifferent_access)))
11
+ super(Fields.new(::Array.wrap(schema).map { |i| HashWithIndifferentAccess.wrap(i) }))
10
12
  end
11
13
 
12
14
  def trim(input)
13
- input.with_indifferent_access.keep_if { |property_name| includes_property?(property_name) }
15
+ HashWithIndifferentAccess.wrap(input).keep_if { |property_name| includes_property?(property_name) }
14
16
  end
15
17
 
16
18
  def apply(input, enforce_required:, &block)
17
- input.with_indifferent_access.tap do |input_with_indifferent_access|
19
+ HashWithIndifferentAccess.wrap(input).tap do |input_with_indifferent_access|
18
20
  apply_to_hash(self, input_with_indifferent_access, enforce_required: enforce_required, &block)
19
21
  end
20
22
  end
@@ -3,6 +3,8 @@
3
3
 
4
4
  require 'active_support/encrypted_configuration'
5
5
 
6
+ using Workato::Extension::HashWithIndifferentAccess
7
+
6
8
  module Workato
7
9
  module Connector
8
10
  module Sdk
@@ -98,13 +100,13 @@ module Workato
98
100
  end
99
101
 
100
102
  def read_encrypted_file
101
- all_settings = encrypted_configuration.config.with_indifferent_access
103
+ all_settings = HashWithIndifferentAccess.wrap(encrypted_configuration.config)
102
104
 
103
105
  (name ? all_settings.fetch(name) : all_settings) || {}
104
106
  end
105
107
 
106
108
  def update_encrypted_file(new_settings)
107
- all_settings = encrypted_configuration.config.with_indifferent_access
109
+ all_settings = HashWithIndifferentAccess.wrap(encrypted_configuration.config)
108
110
 
109
111
  merge_settings(all_settings, new_settings)
110
112
 
@@ -3,6 +3,8 @@
3
3
 
4
4
  require 'securerandom'
5
5
 
6
+ using Workato::Extension::HashWithIndifferentAccess
7
+
6
8
  module Workato
7
9
  module Connector
8
10
  module Sdk
@@ -66,7 +68,6 @@ module Workato
66
68
  ) do |connection, payload, eis, eos|
67
69
  instance_exec(connection, payload[:input], payload[:closure], eis, eos, &poll_proc)
68
70
  end
69
- output.with_indifferent_access
70
71
  output[:events] = Array.wrap(output[:events])
71
72
  .reverse!
72
73
  .map! { |event| ::Hash.try_convert(event) || event }
@@ -135,14 +136,14 @@ module Workato
135
136
  connection.merge_settings!(settings) if settings
136
137
  output = Dsl::WithDsl.execute(
137
138
  connection,
138
- input.with_indifferent_access,
139
+ HashWithIndifferentAccess.wrap(input),
139
140
  payload,
140
- Array.wrap(extended_input_schema).map(&:with_indifferent_access),
141
- Array.wrap(extended_output_schema).map(&:with_indifferent_access),
142
- headers.with_indifferent_access,
143
- params.with_indifferent_access,
141
+ Array.wrap(extended_input_schema).map { |i| HashWithIndifferentAccess.wrap(i) },
142
+ Array.wrap(extended_output_schema).map { |i| HashWithIndifferentAccess.wrap(i) },
143
+ HashWithIndifferentAccess.wrap(headers),
144
+ HashWithIndifferentAccess.wrap(params),
144
145
  connection.settings,
145
- webhook_subscribe_output.with_indifferent_access,
146
+ HashWithIndifferentAccess.wrap(webhook_subscribe_output),
146
147
  &trigger[:webhook_notification]
147
148
  )
148
149
  if output.is_a?(::Array)
@@ -162,7 +163,7 @@ module Workato
162
163
  SorbetTypes::WebhookSubscribeOutputHash
163
164
  )
164
165
  end
165
- def webhook_subscribe(webhook_url = '', settings = nil, input = {}, recipe_id = SecureRandom.uuid)
166
+ def webhook_subscribe(webhook_url = '', settings = nil, input = {}, recipe_id = recipe_id!)
166
167
  webhook_subscribe_proc = trigger[:webhook_subscribe]
167
168
  execute(settings, { input: input, webhook_url: webhook_url, recipe_id: recipe_id }) do |connection, payload|
168
169
  instance_exec(
@@ -4,7 +4,7 @@
4
4
  module Workato
5
5
  module Connector
6
6
  module Sdk
7
- VERSION = '1.1.0'
7
+ VERSION = '1.2.0'
8
8
  end
9
9
  end
10
10
  end
@@ -39,11 +39,13 @@ require 'active_support/all'
39
39
  require 'active_support/json'
40
40
  require_relative '../extension/array'
41
41
  require_relative '../extension/case_sensitive_headers'
42
+ require_relative '../extension/content_encoding_decoder'
42
43
  require_relative '../extension/currency'
43
44
  require_relative '../extension/date'
44
45
  require_relative '../extension/enumerable'
45
46
  require_relative '../extension/extra_chain_cert'
46
47
  require_relative '../extension/hash'
48
+ require_relative '../extension/hash_with_indifferent_access'
47
49
  require_relative '../extension/integer'
48
50
  require_relative '../extension/nil_class'
49
51
  require_relative '../extension/object'
@@ -52,12 +54,12 @@ require_relative '../extension/string'
52
54
  require_relative '../extension/symbol'
53
55
  require_relative '../extension/time'
54
56
 
57
+ require_relative './sdk/errors'
55
58
  require_relative './sdk/account_properties'
56
59
  require_relative './sdk/action'
57
60
  require_relative './sdk/connection'
58
61
  require_relative './sdk/connector'
59
62
  require_relative './sdk/dsl'
60
- require_relative './sdk/errors'
61
63
  require_relative './sdk/lookup_tables'
62
64
  require_relative './sdk/object_definitions'
63
65
  require_relative './sdk/operation'
@@ -67,4 +69,3 @@ require_relative './sdk/summarize'
67
69
  require_relative './sdk/trigger'
68
70
  require_relative './sdk/version'
69
71
  require_relative './sdk/workato_schemas'
70
- require_relative './sdk/xml'
@@ -22,31 +22,6 @@ module Workato
22
22
 
23
23
  ::Net::HTTPHeader.prepend Net::HTTPHeader
24
24
  ::Net::HTTPGenericRequest.prepend Net::HTTPHeader
25
-
26
- module RestClient
27
- module Request
28
- attr_accessor :case_sensitive_headers
29
-
30
- def processed_headers
31
- return @processed_headers if case_sensitive_headers.blank?
32
- return case_sensitive_headers if @processed_headers.blank?
33
-
34
- @processed_headers.merge(case_sensitive_headers)
35
- end
36
-
37
- def execute(&block)
38
- # With 2.0.0+, net/http accepts URI objects in requests and handles wrapping
39
- # IPv6 addresses in [] for use in the Host request header.
40
- net_http_request = net_http_request_class(method).new(uri, processed_headers)
41
- net_http_request.case_sensitive_headers = case_sensitive_headers
42
- transmit(uri, net_http_request, payload, &block)
43
- ensure
44
- payload&.close
45
- end
46
- end
47
- end
48
-
49
- ::RestClient::Request.prepend RestClient::Request
50
25
  end
51
26
  end
52
27
  end
@@ -0,0 +1,67 @@
1
+ # typed: false
2
+ # frozen_string_literal: true
3
+
4
+ module Workato
5
+ module Extension
6
+ module ContentEncodingDecoder
7
+ module RestClient
8
+ module Response
9
+ def create(body, net_http_res, request, start_time)
10
+ body = decode_content_encoding(net_http_res, body)
11
+ super(body, net_http_res, request, start_time)
12
+ end
13
+
14
+ private
15
+
16
+ def decode_content_encoding(response, body)
17
+ content_encoding = response['content-encoding']
18
+
19
+ case content_encoding&.downcase
20
+ when 'deflate', 'gzip', 'x-gzip'
21
+ response.delete 'content-encoding'
22
+ return body if body.blank?
23
+
24
+ deflate_string(body).force_encoding(Encoding.default_external)
25
+ when 'none', 'identity'
26
+ response.delete 'content-encoding'
27
+ body
28
+ else
29
+ body
30
+ end
31
+ end
32
+
33
+ def deflate_string(body)
34
+ # Decodes all deflate, gzip or x-gzip
35
+ zstream = Zlib::Inflate.new(Zlib::MAX_WBITS + 32)
36
+
37
+ zstream.inflate(body) + zstream.finish
38
+ rescue Zlib::DataError
39
+ # No luck with Zlib decompression. Let's try with raw deflate,
40
+ # like some broken web servers do. This part isn't compatible with Net::HTTP content-decoding
41
+ zstream.close
42
+
43
+ zstream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
44
+ zstream.inflate(body) + zstream.finish
45
+ ensure
46
+ zstream.close
47
+ end
48
+ end
49
+ end
50
+
51
+ ::RestClient::Response.singleton_class.prepend(RestClient::Response)
52
+
53
+ ::RestClient::Request.prepend(
54
+ Module.new do
55
+ def default_headers
56
+ # Should pass this header to be compatible with rest-client 2.0.2 version
57
+ # and rely on decode_content_encoding patch
58
+ # since net/http does not decompress response body if Content-Range is specified
59
+ # (see https://github.com/ruby/ruby/blob/27f6ad737b13062339df0a0c80449cf0dbc92ba5/lib/net/http/response.rb#L254)
60
+ # while the previous version of rest-client does.
61
+ super.tap { |headers| headers[:accept_encoding] = 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3' }
62
+ end
63
+ end
64
+ )
65
+ end
66
+ end
67
+ end
@@ -22,20 +22,6 @@ module Workato
22
22
  end
23
23
 
24
24
  ::Net::HTTP.include Net::HTTP
25
-
26
- module RestClient
27
- module Request
28
- attr_accessor :extra_chain_cert
29
-
30
- def net_http_object(hostname, port)
31
- net = super(hostname, port)
32
- net.extra_chain_cert = extra_chain_cert if extra_chain_cert
33
- net
34
- end
35
- end
36
- end
37
-
38
- ::RestClient::Request.prepend RestClient::Request
39
25
  end
40
26
  end
41
27
  end