mirror of
https://github.com/inspec/inspec
synced 2024-11-10 07:04:15 +00:00
switch to faraday as http backend
Signed-off-by: Christoph Hartmann <chris@lollyrock.com>
This commit is contained in:
parent
283bbda0c6
commit
58585e3455
3 changed files with 18 additions and 8 deletions
|
@ -38,5 +38,5 @@ Gem::Specification.new do |spec|
|
|||
spec.add_dependency 'sslshake', '~> 1'
|
||||
spec.add_dependency 'parallel', '~> 1.9'
|
||||
spec.add_dependency 'rspec_junit_formatter', '~> 0.2.3'
|
||||
spec.add_dependency 'http', '~> 2.1.0'
|
||||
spec.add_dependency 'faraday', '>=0.9.0'
|
||||
end
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
# encoding: utf-8
|
||||
# copyright: 2017, Criteo
|
||||
# author: Guilhem Lettron
|
||||
# copyright: 2017, Chef Software Inc
|
||||
# author: Guilhem Lettron, Christoph Hartmann
|
||||
# license: Apache v2
|
||||
|
||||
require 'http'
|
||||
require 'faraday'
|
||||
require 'hashie'
|
||||
|
||||
module Inspec::Resources
|
||||
|
@ -38,7 +39,7 @@ module Inspec::Resources
|
|||
end
|
||||
|
||||
def body
|
||||
response.to_s
|
||||
response.body
|
||||
end
|
||||
|
||||
def headers
|
||||
|
@ -52,9 +53,18 @@ module Inspec::Resources
|
|||
private
|
||||
|
||||
def response
|
||||
http = HTTP.headers(@headers)
|
||||
http = http.basic_auth(@auth) unless @auth.empty?
|
||||
@response ||= http.request(@method, @url, { body: @data, params: @params })
|
||||
conn = Faraday.new url: @url, headers: @headers, params: @params
|
||||
|
||||
# set basic authentication
|
||||
conn.basic_auth @auth[:user], @auth[:pass] unless @auth.empty?
|
||||
|
||||
# set default timeout
|
||||
conn.options.timeout = 5 # open/read timeout in seconds
|
||||
conn.options.open_timeout = 3 # connection open timeout in seconds
|
||||
|
||||
@response = conn.send(@method.downcase) do |req|
|
||||
req.body = @data
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -41,7 +41,7 @@ describe 'Inspec::Resources::Http' do
|
|||
headers: {'content-type' => 'application/json'})
|
||||
_(resource.status).must_equal 200
|
||||
_(resource.body).must_equal 'headers ok'
|
||||
_(resource.headers.Mock).must_equal 'ok'
|
||||
_(resource.headers.mock).must_equal 'ok'
|
||||
end
|
||||
|
||||
it 'verify http with params' do
|
||||
|
|
Loading…
Reference in a new issue