class Inspec::Resources::Http

Public Class Methods

new(url, opts = {}) click to toggle source
# File lib/inspec/resources/http.rb, line 28
def initialize(url, opts = {})
  @url = url
  @opts = opts

  # Prior to InSpec 2.0 the HTTP test had to be instructed to run on the
  # remote target machine. This warning will be removed after a few months
  # to give users an opportunity to remove the unused option from their
  # profiles.
  if opts.key?(:enable_remote_worker) && !inspec.local_transport?
    warn "Ignoring `enable_remote_worker` option, the `http` resource ",
         "remote worker is enabled by default for remote targets and ",
         "cannot be disabled"
  end

  # Run locally if InSpec is ran locally and remotely if ran remotely
  if inspec.local_transport?
    @worker = Worker::Local.new(http_method, url, opts)
  else
    @worker = Worker::Remote.new(inspec, http_method, url, opts)
  end
end

Public Instance Methods

body() click to toggle source
# File lib/inspec/resources/http.rb, line 58
def body
  @worker.body&.force_encoding(Encoding::UTF_8)
end
headers() click to toggle source
# File lib/inspec/resources/http.rb, line 54
def headers
  @headers ||= Inspec::Resources::Http::Headers.create(@worker.response_headers)
end
http_method() click to toggle source
# File lib/inspec/resources/http.rb, line 62
def http_method
  @opts.fetch(:method, "GET")
end
status() click to toggle source
# File lib/inspec/resources/http.rb, line 50
def status
  @worker.status
end
to_s() click to toggle source
# File lib/inspec/resources/http.rb, line 66
def to_s
  if @opts && @url
    "HTTP #{http_method} on #{@url}"
  else
    "HTTP Resource"
  end
end