Class: Outpost::Scouts::Http
- Inherits:
-
Outpost::Scout
- Object
- Outpost::Scout
- Outpost::Scouts::Http
- Defined in:
- lib/outpost/scouts/http.rb
Overview
Uses ruby’s own Net:HTTP to send HTTP requests and evaluate response body, response time and response code.
-
Responds to response_time expectation (Expectations::ResponseTime)
-
Responds to response_code expectation (Expectations::ResponseCode)
-
Responds to response_body expectation (Expectations::ResponseBody)
Constant Summary
Constants included from Expectations::ResponseTime
Expectations::ResponseTime::RESPONSE_TIME_MAPPING
Instance Attribute Summary collapse
-
#response_body ⇒ Object
readonly
Returns the value of attribute response_body.
-
#response_code ⇒ Object
readonly
Returns the value of attribute response_code.
-
#response_time ⇒ Object
readonly
Returns the value of attribute response_time.
Attributes inherited from Outpost::Scout
Instance Method Summary collapse
-
#execute ⇒ Object
Runs the scout, connecting to the host and getting the response code, body and time.
-
#setup(options) ⇒ Object
Configure the scout with given options.
Methods included from Expectations::ResponseCode
evaluate_response_code, extended
Methods included from Expectations::ResponseBody
evaluate_response_body, extended
Methods included from Expectations::ResponseTime
evaluate_response_time, extended
Methods inherited from Outpost::Scout
expect, expectations, #gather_reporting_data, #initialize, report_data, #run
Constructor Details
This class inherits a constructor from Outpost::Scout
Instance Attribute Details
#response_body ⇒ Object (readonly)
Returns the value of attribute response_body.
21 22 23 |
# File 'lib/outpost/scouts/http.rb', line 21 def response_body @response_body end |
#response_code ⇒ Object (readonly)
Returns the value of attribute response_code.
21 22 23 |
# File 'lib/outpost/scouts/http.rb', line 21 def response_code @response_code end |
#response_time ⇒ Object (readonly)
Returns the value of attribute response_time.
21 22 23 |
# File 'lib/outpost/scouts/http.rb', line 21 def response_time @response_time end |
Instance Method Details
#execute ⇒ Object
Runs the scout, connecting to the host and getting the response code, body and time.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/outpost/scouts/http.rb', line 41 def execute previous_time = Time.now response = @http_class.get_response(@host, @path, @port) @response_time = (Time.now - previous_time) * 1000 # Miliseconds @response_code = response.code.to_i @response_body = response.body rescue SocketError, Errno::ECONNREFUSED @response_code = @response_body = @response_time = nil end |
#setup(options) ⇒ Object
Configure the scout with given options.
32 33 34 35 36 37 |
# File 'lib/outpost/scouts/http.rb', line 32 def setup() @host = [:host] @port = [:port] || 80 @path = [:path] || '/' @http_class = [:http_class] || Net::HTTP end |