Class: Inspec::Resources::Http

Inherits:
Object
  • Object
show all
Defined in:
lib/resources/http.rb

Defined Under Namespace

Classes: Headers, Worker

Instance Method Summary collapse

Constructor Details

#initialize(url, opts = {}) ⇒ Http

Returns a new instance of Http.



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/resources/http.rb', line 33

def initialize(url, opts = {})
  @url = url
  @opts = opts

  if use_remote_worker?
    return skip_resource 'curl is not available on the target machine' unless inspec.command('curl').exist?
    @worker = Worker::Remote.new(inspec, http_method, url, opts)
  else
    @worker = Worker::Local.new(http_method, url, opts)
  end
end

Instance Method Details

#bodyObject



53
54
55
# File 'lib/resources/http.rb', line 53

def body
  @worker.body
end

#headersObject



49
50
51
# File 'lib/resources/http.rb', line 49

def headers
  @headers ||= Inspec::Resources::Http::Headers.create(@worker.response_headers)
end

#http_methodObject



57
58
59
# File 'lib/resources/http.rb', line 57

def http_method
  @opts.fetch(:method, 'GET')
end

#statusObject



45
46
47
# File 'lib/resources/http.rb', line 45

def status
  @worker.status
end

#to_sObject



61
62
63
# File 'lib/resources/http.rb', line 61

def to_s
  "http #{http_method} on #{@url}"
end