Class: Falcon::Host

Inherits:
Object
  • Object
show all
Defined in:
lib/falcon/hosts.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHost

Returns a new instance of Host.



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/falcon/hosts.rb', line 30

def initialize
	@app = nil
	@app_root = nil
	@config_path = "config.ru"
	
	@endpoint = nil
	
	@ssl_certificate = nil
	@ssl_key = nil
	
	@ssl_context = nil
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



43
44
45
# File 'lib/falcon/hosts.rb', line 43

def app
  @app
end

#app_rootObject

Returns the value of attribute app_root.



44
45
46
# File 'lib/falcon/hosts.rb', line 44

def app_root
  @app_root
end

#config_pathObject

Returns the value of attribute config_path.



45
46
47
# File 'lib/falcon/hosts.rb', line 45

def config_path
  @config_path
end

#endpointObject

Returns the value of attribute endpoint.



47
48
49
# File 'lib/falcon/hosts.rb', line 47

def endpoint
  @endpoint
end

#ssl_certificateObject

Returns the value of attribute ssl_certificate.



49
50
51
# File 'lib/falcon/hosts.rb', line 49

def ssl_certificate
  @ssl_certificate
end

#ssl_contextObject

Returns the value of attribute ssl_context.



52
53
54
# File 'lib/falcon/hosts.rb', line 52

def ssl_context
  @ssl_context
end

#ssl_keyObject

Returns the value of attribute ssl_key.



50
51
52
# File 'lib/falcon/hosts.rb', line 50

def ssl_key
  @ssl_key
end

Instance Method Details

#app?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/falcon/hosts.rb', line 62

def app?
	@app || @config_path
end

#freezeObject



54
55
56
57
58
59
60
# File 'lib/falcon/hosts.rb', line 54

def freeze
	return if frozen?
	
	ssl_context
	
	super
end

#load_app(verbose = false) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/falcon/hosts.rb', line 66

def load_app(verbose = false)
	return @app if @app
	
	if @config_path
		rack_app, options = Rack::Builder.parse_file(@config_path)
		
		return Server.middleware(rack_app, verbose: verbose)
	end
end

#self_signed!(hostname) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/falcon/hosts.rb', line 76

def self_signed!(hostname)
	authority = Localhost::Authority.fetch(hostname)
	
	@ssl_context = authority.server_context.tap do |context|
		context.alpn_select_cb = lambda do |protocols|
			if protocols.include? "h2"
				return "h2"
			elsif protocols.include? "http/1.1"
				return "http/1.1"
			elsif protocols.include? "http/1.0"
				return "http/1.0"
			else
				return nil
			end
		end
		
		context.session_id_context = "falcon"
	end
end

#ssl_certificate_path=(path) ⇒ Object



96
97
98
# File 'lib/falcon/hosts.rb', line 96

def ssl_certificate_path= path
	@ssl_certificate = OpenSSL::X509::Certificate.new(File.read(path))
end

#ssl_key_path=(path) ⇒ Object



100
101
102
# File 'lib/falcon/hosts.rb', line 100

def ssl_key_path= path
	@ssl_key = OpenSSL::PKey::RSA.new(File.read(path))
end

#start(*args) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/falcon/hosts.rb', line 117

def start(*args)
	if self.app?
		Async::Container::Forked.new do
			Dir.chdir(@app_root) if @app_root
			
			app = self.load_app(*args)
			
			server = Falcon::Server.new(app, self.server_endpoint)
			
			server.run
		end
	end
end