grac 4.4.1 → 4.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '014856f6d0cb348e58f94c2a6af0219e6e3cf8cfc7e347702dd31fee356132a8'
4
- data.tar.gz: 366ff7b21060668da66611517675a45e5102fda1d321d393bc6b84319fa3ba33
3
+ metadata.gz: 3b2bebcc4e909adb1e0cf7a05e6c710c4de2491ab29c506975d559367c9e1be3
4
+ data.tar.gz: dcd944e2ce073ce3dca7d9b44cc0be1b2e8834bdc1af7de9f1aa7c0b1c7fec32
5
5
  SHA512:
6
- metadata.gz: ed2781017bd764ac99b6a1bbab63095d174fbd5682fc9fb170c19ee56d27907f386301b920c0c795786d84889361db80be1db48b43ce431409370f289babac08
7
- data.tar.gz: 616322e1feeccffb38acf4ad5a30d9ca58e8bc7878690401ccff7768e8f679a198e851bc99f24ef4f52272b9836fcaff47b2055980663f29d4b6b6a19c6731e3
6
+ metadata.gz: 108fb0cd4c2a9a0864d71a3b36697c7905ecb034443e49de1b701264f21980c5c469928ebcd44f9289bfdeef60016eb9819db9a757d2f6d64973ea1d8293998c
7
+ data.tar.gz: bdb4308590bf1abf18b0d31a45c208576b79ba9856a19913348e83c1d11957aff0a41e69de589bb651961bdfa340e9977487aaf4eb3771afb5e7cde849e57482
data/lib/grac/client.rb CHANGED
@@ -97,6 +97,7 @@ module Grac
97
97
  }
98
98
  apply_proxy_options(request_hash, opts[:proxy])
99
99
  apply_ssl_options(request_hash, opts[:ssl])
100
+ apply_multipart_handling(request_hash, opts[:headers])
100
101
 
101
102
  request = ::Typhoeus::Request.new(request_uri, request_hash)
102
103
  response = request.run
@@ -151,6 +152,9 @@ module Grac
151
152
  when /\Aapplication\/x-www-form-urlencoded/
152
153
  # Typhoeus will take care of the encoding when receiving a hash
153
154
  return body
155
+ when /\Amultipart\/form-data/
156
+ # Typhoeus will take care of the encoding when receiving a hash
157
+ return body
154
158
  else
155
159
  # Do not encode other unknown Content-Types either.
156
160
  # The default is JSON through the Content-Type header which is set by default.
@@ -162,7 +166,7 @@ module Grac
162
166
  callee = self
163
167
 
164
168
  @options[:middleware].reverse.each do |mw|
165
- if mw.kind_of?(Array)
169
+ if mw.is_a?(Array)
166
170
  middleware_class = mw[0]
167
171
  params = mw[1..-1]
168
172
 
@@ -220,17 +224,17 @@ module Grac
220
224
  def postprocessing(data, processing = nil)
221
225
  return data if @options[:postprocessing].nil? || @options[:postprocessing].empty?
222
226
 
223
- if data.kind_of?(Hash)
227
+ if data.is_a?(Hash)
224
228
  data.each do |key, value|
225
229
  processing = nil
226
230
  regexp = @options[:postprocessing].keys.detect { |pattern| pattern.match?(key) }
227
231
 
228
- if !regexp.nil?
232
+ if regexp != nil
229
233
  processing = @options[:postprocessing][regexp]
230
234
  end
231
235
  data[key] = postprocessing(value, processing)
232
236
  end
233
- elsif data.kind_of?(Array)
237
+ elsif data.is_a?(Array)
234
238
  data.each_with_index do |value, index|
235
239
  data[index] = postprocessing(value, processing)
236
240
  end
@@ -279,5 +283,17 @@ module Grac
279
283
  request_hash[:cainfo] = ssl[:ca_info] if ssl[:ca_info] != nil
280
284
  end
281
285
 
286
+ def apply_multipart_handling(request_hash, headers)
287
+ return if headers == nil
288
+ return if !headers['Content-Type']
289
+ return if !headers['Content-Type'].include?('multipart/form-data')
290
+
291
+ request_hash[:multipart] = true
292
+ # Typhoeus does not expect a Content-Type header for multipart requests.
293
+ # It sets the correct one itself including the boundary.
294
+ # Therefore we need to remove the Content-Type header from the request.
295
+ request_hash[:headers] = headers.reject { |k, _| k == 'Content-Type' }
296
+ end
297
+
282
298
  end
283
299
  end
data/lib/grac/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Grac
4
4
 
5
- VERSION = '4.4.1'
5
+ VERSION = '4.5.0'
6
6
 
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grac
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.1
4
+ version: 4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Schoknecht