Class: Capybara::Server Private
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Inherits: | Object |
Defined in: | lib/capybara/server.rb, lib/capybara/server/animation_disabler.rb, lib/capybara/server/checker.rb, lib/capybara/server/middleware.rb |
Class Method Summary
- .new(app, *deprecated_options, port: Capybara.server_port, host: Capybara.server_host, reportable_errors: Capybara.server_errors, extra_middleware: []) ⇒ Server constructor Internal use only Internal use only
- .ports Internal use only Internal use only
Instance Attribute Summary
- #app readonly Internal use only Internal use only
- #host readonly Internal use only Internal use only
- #port readonly Internal use only Internal use only
- #responsive? ⇒ Boolean readonly Internal use only Internal use only
- #using_ssl? ⇒ Boolean readonly Internal use only Internal use only
- #pending_requests? ⇒ Boolean readonly private Internal use only Internal use only
Instance Method Summary
- #base_url Internal use only Internal use only
- #boot Internal use only Internal use only
- #error Internal use only Internal use only
- #reset_error! Internal use only Internal use only
- #wait_for_pending_requests Internal use only Internal use only
- #find_available_port(host) private Internal use only Internal use only
- #middleware private Internal use only Internal use only
- #port_key private Internal use only Internal use only
Constructor Details
.new(app, *deprecated_options, port: Capybara.server_port, host: Capybara.server_host, reportable_errors: Capybara.server_errors, extra_middleware: []) ⇒ Server
This method is for internal use only.
# File 'lib/capybara/server.rb', line 21
def initialize(app, *, port: Capybara.server_port, host: Capybara.server_host, reportable_errors: Capybara.server_errors, extra_middleware: []) unless .empty? warn 'Positional arguments, other than the application, to Server#new are deprecated, please use keyword arguments' end @app = app @extra_middleware = extra_middleware @server_thread = nil # suppress warnings @host = [1] || host @reportable_errors = [2] || reportable_errors @port = [0] || port @port ||= Capybara::Server.ports[port_key] @port ||= find_available_port(host) @checker = Checker.new(@host, @port) end
Class Method Details
.ports
This method is for internal use only.
[ GitHub ]
# File 'lib/capybara/server.rb', line 14
def ports @ports ||= {} end
Instance Attribute Details
#app (readonly)
This method is for internal use only.
[ GitHub ]
#host (readonly)
This method is for internal use only.
[ GitHub ]
#pending_requests? ⇒ Boolean
(readonly, private)
This method is for internal use only.
# File 'lib/capybara/server.rb', line 105
def pending_requests? middleware.pending_requests? end
#port (readonly)
This method is for internal use only.
[ GitHub ]
#responsive? ⇒ Boolean
(readonly)
This method is for internal use only.
# File 'lib/capybara/server.rb', line 53
def responsive? return false if @server_thread&.join(0) res = @checker.request { |http| http.get('/__identify__') } res.body == app.object_id.to_s if res.is_a?(Net::HTTPSuccess) || res.is_a?(Net::HTTPRedirection) rescue SystemCallError, Net::ReadTimeout, OpenSSL::SSL::SSLError false end
#using_ssl? ⇒ Boolean
(readonly)
This method is for internal use only.
# File 'lib/capybara/server.rb', line 49
def using_ssl? @checker.ssl? end
Instance Method Details
#base_url
This method is for internal use only.
[ GitHub ]
# File 'lib/capybara/server.rb', line 91
def base_url "http#{'s' if using_ssl?}://#{host}:#{port}" end
#boot
This method is for internal use only.
[ GitHub ]
# File 'lib/capybara/server.rb', line 72
def boot unless responsive? Capybara::Server.ports[port_key] = port @server_thread = Thread.new do Capybara.server.call(middleware, port, host) end timer = Capybara::Helpers.timer(expire_in: 60) until responsive? raise 'Rack application timed out during boot' if timer.expired? @server_thread.join(0.1) end end self end
#error
This method is for internal use only.
[ GitHub ]
# File 'lib/capybara/server.rb', line 45
def error middleware.error end
#find_available_port(host) (private)
This method is for internal use only.
[ GitHub ]
# File 'lib/capybara/server.rb', line 109
def find_available_port(host) server = TCPServer.new(host, 0) port = server.addr[1] server.close # Workaround issue where some platforms (mac, ???) when passed a host # of '0.0.0.0' will return a port that is only available on one of the # ip addresses that resolves to, but the next binding to that port requires # that port to be available on all ips server = TCPServer.new(host, port) port rescue Errno::EADDRINUSE retry ensure server&.close end
#middleware (private)
This method is for internal use only.
[ GitHub ]
# File 'lib/capybara/server.rb', line 97
def middleware @middleware ||= Middleware.new(app, @reportable_errors, @extra_middleware) end
#port_key (private)
This method is for internal use only.
[ GitHub ]
# File 'lib/capybara/server.rb', line 101
def port_key Capybara.reuse_server ? app.object_id : middleware.object_id end
#reset_error!
This method is for internal use only.
[ GitHub ]
# File 'lib/capybara/server.rb', line 41
def reset_error! middleware.clear_error end
#wait_for_pending_requests
This method is for internal use only.
[ GitHub ]
# File 'lib/capybara/server.rb', line 63
def wait_for_pending_requests timer = Capybara::Helpers.timer(expire_in: 60) while pending_requests? raise "Requests did not finish in 60 seconds: #{middleware.pending_requests}" if timer.expired? sleep 0.01 end end