Class: Concuss::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/concuss/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(headers:, url:, test_string: nil) ⇒ Runner

Returns a new instance of Runner.



7
8
9
10
11
# File 'lib/concuss/runner.rb', line 7

def initialize(headers:, url:, test_string: nil)
  @headers = headers
  @url = url
  @test_string = test_string || SecureRandom.hex(25)
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



5
6
7
# File 'lib/concuss/runner.rb', line 5

def headers
  @headers
end

#test_stringObject (readonly)

Returns the value of attribute test_string.



5
6
7
# File 'lib/concuss/runner.rb', line 5

def test_string
  @test_string
end

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'lib/concuss/runner.rb', line 5

def url
  @url
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/concuss/runner.rb', line 13

def run
  uri = URI(@url)

  @headers.each do |header|
    response = Net::HTTP.get_response(uri,
      { header => test_string }
    )

    if response.code == "200" && response.body.include?(@test_string)
      result = "HIT"
    else
      result = "MISS"
    end

    puts "#{header} - #{response.code} - #{result}"
  end
end