Class: Rack::Padlock::Server
- Inherits:
-
Object
- Object
- Rack::Padlock::Server
- Defined in:
- lib/rack/padlock/server.rb
Constant Summary collapse
- PORT =
9988
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
Instance Method Summary collapse
- #base_uri ⇒ Object
- #boot ⇒ Object
-
#initialize(app) ⇒ Server
constructor
A new instance of Server.
- #responsive? ⇒ Boolean
Constructor Details
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
8 9 10 |
# File 'lib/rack/padlock/server.rb', line 8 def app @app end |
Instance Method Details
#base_uri ⇒ Object
45 46 47 |
# File 'lib/rack/padlock/server.rb', line 45 def base_uri "https://localhost:#{PORT}" end |
#boot ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rack/padlock/server.rb', line 16 def boot @server_thread = Thread.new do webserver = Rack::Padlock::Webrick.run(@middleware, PORT) end Timeout.timeout(60) { @server_thread.join(0.1) until responsive? } rescue Timeout::Error raise "Rack application timed out during boot" else self end |
#responsive? ⇒ Boolean
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rack/padlock/server.rb', line 28 def responsive? return false if @server_thread && @server_thread.join(0) require "net/https" require 'uri' uri = URI.parse("#{base_uri}/padlock_middleware/poke") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(uri.request_uri) response = http.request(request) return response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPRedirection) rescue Errno::ECONNREFUSED, Errno::EBADF return false end |