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.
22 23 24 |
# File 'lib/outpost/scouts/http.rb', line 22 def response_body @response_body end |
#response_code ⇒ Object (readonly)
Returns the value of attribute response_code.
22 23 24 |
# File 'lib/outpost/scouts/http.rb', line 22 def response_code @response_code end |
#response_time ⇒ Object (readonly)
Returns the value of attribute response_time.
22 23 24 |
# File 'lib/outpost/scouts/http.rb', line 22 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.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/outpost/scouts/http.rb', line 45 def execute previous_time = Time.now if @request_head response = @http_class.request_head(@host, @path, @port) else uri = (@ssl ? URI::HTTPS : URI::HTTP).build({ host: @host, port: @port, path: @path }) http = @http_class.new(uri.host, uri.port) http.use_ssl = @ssl request = @http_class::Get.new(uri.request_uri) response = http.request(request) end @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.
34 35 36 37 38 39 40 41 |
# File 'lib/outpost/scouts/http.rb', line 34 def setup() @host = .fetch(:host) @path = .fetch(:path, '/') @ssl = .fetch(:ssl, false) @port = .fetch(:port, (@ssl ? 443 : 80)) @http_class = .fetch(:http_class, Net::HTTP) @request_head = .fetch(:request_head, false) end |