Method: Compliance::HTTP.post_multipart_file

Defined in:
lib/bundles/inspec-compliance/http.rb

.post_multipart_file(url, headers, file_path, insecure) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/bundles/inspec-compliance/http.rb', line 72

def self.post_multipart_file(url, headers, file_path, insecure)
  uri = _parse_url(url)
  raise "Unable to parse URL: #{url}" if uri.nil? || uri.host.nil?
  http = Net::HTTP.new(uri.host, uri.port)

  # set connection flags
  http.use_ssl = (uri.scheme == 'https')
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE if insecure

  File.open(file_path) do |tar|
    req = Net::HTTP::Post::Multipart.new(uri, 'file' => UploadIO.new(tar, 'application/x-gzip', File.basename(file_path)))
    headers.each do |key, value|
      req.add_field(key, value)
    end
    res = http.request(req)
    return res
  end
end