falcon 0.42.3 → 0.44.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/bake/falcon/supervisor.rb +3 -1
  4. data/changes.md +22 -0
  5. data/lib/falcon/command/host.rb +7 -50
  6. data/lib/falcon/command/paths.rb +2 -19
  7. data/lib/falcon/command/proxy.rb +21 -33
  8. data/lib/falcon/command/redirect.rb +22 -33
  9. data/lib/falcon/command/serve.rb +44 -82
  10. data/lib/falcon/command/supervisor.rb +2 -19
  11. data/lib/falcon/command/top.rb +2 -19
  12. data/lib/falcon/command/virtual.rb +16 -41
  13. data/lib/falcon/command.rb +3 -19
  14. data/lib/falcon/configuration.rb +28 -142
  15. data/lib/falcon/endpoint.rb +2 -19
  16. data/lib/falcon/environment/application.rb +60 -0
  17. data/lib/falcon/environment/lets_encrypt_tls.rb +34 -0
  18. data/lib/falcon/environment/proxy.rb +109 -0
  19. data/lib/falcon/environment/rack.rb +20 -0
  20. data/lib/falcon/environment/rackup.rb +26 -0
  21. data/lib/falcon/environment/redirect.rb +50 -0
  22. data/lib/falcon/environment/self_signed_tls.rb +45 -0
  23. data/lib/falcon/environment/server.rb +69 -0
  24. data/lib/falcon/environment/supervisor.rb +40 -0
  25. data/lib/falcon/environment/tls.rb +97 -0
  26. data/lib/falcon/environment.rb +13 -0
  27. data/lib/falcon/middleware/proxy.rb +3 -20
  28. data/lib/falcon/middleware/redirect.rb +2 -19
  29. data/lib/falcon/middleware/verbose.rb +2 -19
  30. data/lib/falcon/proxy_endpoint.rb +2 -19
  31. data/lib/falcon/railtie.rb +10 -0
  32. data/lib/falcon/server.rb +2 -19
  33. data/lib/falcon/service/server.rb +84 -0
  34. data/lib/falcon/service/supervisor.rb +5 -21
  35. data/lib/falcon/{controller → service}/virtual.rb +72 -36
  36. data/lib/falcon/tls.rb +2 -19
  37. data/lib/falcon/version.rb +3 -20
  38. data/lib/falcon.rb +5 -19
  39. data/lib/rack/handler/falcon.rb +4 -0
  40. data/lib/rackup/handler/falcon.rb +83 -0
  41. data/license.md +41 -0
  42. data/readme.md +60 -0
  43. data.tar.gz.sig +0 -0
  44. metadata +37 -117
  45. metadata.gz.sig +0 -0
  46. data/lib/.DS_Store +0 -0
  47. data/lib/falcon/controller/host.rb +0 -72
  48. data/lib/falcon/controller/proxy.rb +0 -126
  49. data/lib/falcon/controller/redirect.rb +0 -76
  50. data/lib/falcon/controller/serve.rb +0 -126
  51. data/lib/falcon/environments/application.rb +0 -72
  52. data/lib/falcon/environments/lets_encrypt_tls.rb +0 -47
  53. data/lib/falcon/environments/proxy.rb +0 -37
  54. data/lib/falcon/environments/rack.rb +0 -50
  55. data/lib/falcon/environments/self_signed_tls.rb +0 -55
  56. data/lib/falcon/environments/supervisor.rb +0 -51
  57. data/lib/falcon/environments/tls.rb +0 -103
  58. data/lib/falcon/environments.rb +0 -31
  59. data/lib/falcon/service/application.rb +0 -115
  60. data/lib/falcon/service/generic.rb +0 -78
  61. data/lib/falcon/service/proxy.rb +0 -66
  62. data/lib/falcon/services.rb +0 -99
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2019-2024, by Samuel Williams.
5
+
6
+ require_relative '../service/supervisor'
7
+ require_relative '../environment'
8
+
9
+ module Falcon
10
+ module Environment
11
+ # Provides an environment for hosting a supervisor which can monitor multiple applications.
12
+ module Supervisor
13
+ # The name of the supervisor
14
+ # @returns [String]
15
+ def name
16
+ "supervisor"
17
+ end
18
+
19
+ # The IPC path to use for communication with the supervisor.
20
+ # @returns [String]
21
+ def ipc_path
22
+ ::File.expand_path("supervisor.ipc", root)
23
+ end
24
+
25
+ # The endpoint the supervisor will bind to.
26
+ # @returns [Async::IO::Endpoint]
27
+ def endpoint
28
+ Async::IO::Endpoint.unix(ipc_path)
29
+ end
30
+
31
+ # The service class to use for the supervisor.
32
+ # @returns [Class]
33
+ def service_class
34
+ ::Falcon::Service::Supervisor
35
+ end
36
+ end
37
+
38
+ LEGACY_ENVIRONMENTS[:supervisor] = Supervisor
39
+ end
40
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2019-2024, by Samuel Williams.
5
+
6
+ require_relative '../tls'
7
+ require_relative '../environment'
8
+
9
+ module Falcon
10
+ module Environment
11
+ # Provides an environment that exposes a TLS context for hosting a secure web application.
12
+ module TLS
13
+ # The default session identifier for the session cache.
14
+ # @returns [String]
15
+ def ssl_session_id
16
+ "falcon"
17
+ end
18
+
19
+ # The supported ciphers.
20
+ # @returns [Array(String)]
21
+ def ssl_ciphers
22
+ Falcon::TLS::SERVER_CIPHERS
23
+ end
24
+
25
+ # The public certificate path.
26
+ # @returns [String]
27
+ def ssl_certificate_path
28
+ File.expand_path("ssl/certificate.pem", root)
29
+ end
30
+
31
+ # The list of certificates loaded from that path.
32
+ # @returns [Array(OpenSSL::X509::Certificate)]
33
+ def ssl_certificates
34
+ OpenSSL::X509::Certificate.load_file(ssl_certificate_path)
35
+ end
36
+
37
+ # The main certificate.
38
+ # @returns [OpenSSL::X509::Certificate]
39
+ def ssl_certificate
40
+ ssl_certificates[0]
41
+ end
42
+
43
+ # The certificate chain.
44
+ # @returns [Array(OpenSSL::X509::Certificate)]
45
+ def ssl_certificate_chain
46
+ ssl_certificates[1..-1]
47
+ end
48
+
49
+ # The private key path.
50
+ # @returns [String]
51
+ def ssl_private_key_path
52
+ File.expand_path("ssl/private.key", root)
53
+ end
54
+
55
+ # The private key.
56
+ # @returns [OpenSSL::PKey::RSA]
57
+ def ssl_private_key
58
+ OpenSSL::PKey::RSA.new(File.read(ssl_private_key_path))
59
+ end
60
+
61
+ # The SSL context to use for incoming connections.
62
+ # @returns [OpenSSL::SSL::SSLContext]
63
+ def ssl_context
64
+ OpenSSL::SSL::SSLContext.new.tap do |context|
65
+ context.add_certificate(ssl_certificate, ssl_private_key, ssl_certificate_chain)
66
+
67
+ context.session_cache_mode = OpenSSL::SSL::SSLContext::SESSION_CACHE_CLIENT
68
+ context.session_id_context = ssl_session_id
69
+
70
+ context.alpn_select_cb = lambda do |protocols|
71
+ if protocols.include? "h2"
72
+ return "h2"
73
+ elsif protocols.include? "http/1.1"
74
+ return "http/1.1"
75
+ elsif protocols.include? "http/1.0"
76
+ return "http/1.0"
77
+ else
78
+ return nil
79
+ end
80
+ end
81
+
82
+ # TODO Ruby 2.4 requires using ssl_version.
83
+ context.ssl_version = :TLSv1_2_server
84
+
85
+ context.set_params(
86
+ ciphers: ssl_ciphers,
87
+ verify_mode: OpenSSL::SSL::VERIFY_NONE,
88
+ )
89
+
90
+ context.setup
91
+ end
92
+ end
93
+ end
94
+
95
+ LEGACY_ENVIRONMENTS[:tls] = TLS
96
+ end
97
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2019-2024, by Samuel Williams.
5
+
6
+ module Falcon
7
+ # Pre-defined environments for hosting web applications.
8
+ #
9
+ # See {Configuration::Loader#load} for more details.
10
+ module Environment
11
+ LEGACY_ENVIRONMENTS = {}
12
+ end
13
+ end
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2018-2023, by Samuel Williams.
22
5
 
23
6
  require 'async/http/client'
24
7
  require 'protocol/http/headers'
@@ -58,7 +41,7 @@ module Falcon
58
41
 
59
42
  # Initialize the proxy middleware.
60
43
  # @parameter app [Protocol::HTTP::Middleware] The middleware to use if a request can't be proxied.
61
- # @parameter hosts [Array(Service::Proxy)] The host applications to proxy to.
44
+ # @parameter hosts [Hash(String, Service::Proxy)] The host applications to proxy to.
62
45
  def initialize(app, hosts)
63
46
  super(app)
64
47
 
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2018-2023, by Samuel Williams.
22
5
 
23
6
  require 'async/http/client'
24
7
 
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2018-2023, by Samuel Williams.
22
5
 
23
6
  require 'console'
24
7
  require 'async/http/statistics'
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2019-2023, by Samuel Williams.
22
5
 
23
6
  require 'async/io/unix_endpoint'
24
7
 
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2024, by Samuel Williams.
5
+
6
+ module Falcon
7
+ class Railtie < Rails::Railtie
8
+ config.active_support.isolation_level = :fiber
9
+ end
10
+ end
data/lib/falcon/server.rb CHANGED
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2017-2023, by Samuel Williams.
22
5
 
23
6
  require 'async/http/server'
24
7
 
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2020-2024, by Samuel Williams.
5
+ # Copyright, 2020, by Michael Adams.
6
+
7
+ require 'async/service/generic'
8
+ require 'async/http/endpoint'
9
+
10
+ require_relative '../server'
11
+
12
+ module Falcon
13
+ module Service
14
+ class Server < Async::Service::Generic
15
+ def initialize(...)
16
+ super
17
+
18
+ @bound_endpoint = nil
19
+ end
20
+
21
+ # Preload any resources specified by the environment.
22
+ def preload!
23
+ root = @evaluator.root
24
+
25
+ if scripts = @evaluator.preload
26
+ scripts = Array(scripts)
27
+
28
+ scripts.each do |path|
29
+ Console.logger.info(self) {"Preloading #{path}..."}
30
+ full_path = File.expand_path(path, root)
31
+ load(full_path)
32
+ end
33
+ end
34
+ end
35
+
36
+ # Prepare the bound endpoint for the server.
37
+ def start
38
+ @endpoint = @evaluator.endpoint
39
+
40
+ Sync do
41
+ @bound_endpoint = @endpoint.bound
42
+ end
43
+
44
+ preload!
45
+
46
+ Console.logger.info(self) {"Starting #{self.name} on #{@endpoint}"}
47
+
48
+ super
49
+ end
50
+
51
+ # Setup the container with the application instance.
52
+ # @parameter container [Async::Container::Generic]
53
+ def setup(container)
54
+ container_options = @evaluator.container_options
55
+
56
+ container.run(name: self.name, **container_options) do |instance|
57
+ evaluator = @environment.evaluator
58
+
59
+ Async do |task|
60
+ server = Falcon::Server.new(evaluator.middleware, @bound_endpoint, protocol: @endpoint.protocol, scheme: @endpoint.scheme)
61
+
62
+ server.run
63
+
64
+ instance.ready!
65
+
66
+ task.children.each(&:wait)
67
+ end
68
+ end
69
+ end
70
+
71
+ # Close the bound endpoint.
72
+ def stop(...)
73
+ if @bound_endpoint
74
+ @bound_endpoint.close
75
+ @bound_endpoint = nil
76
+ end
77
+
78
+ @endpoint = nil
79
+
80
+ super
81
+ end
82
+ end
83
+ end
84
+ end
@@ -1,38 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2019-2024, by Samuel Williams.
22
5
 
23
6
  require 'process/metrics'
24
7
  require 'json'
25
8
 
26
9
  require 'async/io/endpoint'
27
10
  require 'async/io/shared_endpoint'
11
+ require 'async/service/generic'
28
12
 
29
13
  module Falcon
30
14
  module Service
31
15
  # Implements a host supervisor which can restart the host services and provide various metrics about the running processes.
32
- class Supervisor < Generic
16
+ class Supervisor < Async::Service::Generic
33
17
  # Initialize the supervisor using the given environment.
34
18
  # @parameter environment [Build::Environment]
35
- def initialize(environment)
19
+ def initialize(...)
36
20
  super
37
21
 
38
22
  @bound_endpoint = nil
@@ -1,42 +1,76 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2024, by Samuel Williams.
22
5
 
23
- require 'async/container/controller'
6
+ require 'async/service/generic'
24
7
 
25
8
  module Falcon
26
- module Controller
9
+ module Service
27
10
  # A controller which mananages several virtual hosts.
28
11
  # Spawns instances of {Proxy} and {Redirect} to handle incoming requests.
29
12
  #
30
13
  # A virtual host is an application bound to a specific authority (essentially a hostname). The virtual controller manages multiple hosts and allows a single server to host multiple applications easily.
31
- class Virtual < Async::Container::Controller
32
- # Initialize the virtual controller.
33
- # @parameter command [Command::Virtual] The user-specified command-line options.
34
- def initialize(command, **options)
35
- @command = command
14
+ class Virtual < Async::Service::Generic
15
+ module Environment
16
+ # The service class to use for the virtual host.
17
+ # @returns [Class]
18
+ def service_class
19
+ Virtual
20
+ end
21
+
22
+ def name
23
+ service_class.name
24
+ end
25
+
26
+ # All the falcon application configuration paths.
27
+ # @returns [Array(String)] Paths to the falcon application configuration files.
28
+ def configuration_paths
29
+ ["/srv/http/*/falcon.rb"]
30
+ end
36
31
 
37
- super(**options)
32
+ def configuration
33
+ ::Async::Service::Configuration.load(configuration_paths)
34
+ end
35
+
36
+ # The URI to bind the `HTTPS` -> `falcon host` proxy.
37
+ def bind_secure
38
+ "https://[::]:443"
39
+ end
40
+
41
+ # The URI to bind the `HTTP` -> `HTTPS` redirector.
42
+ def bind_insecure
43
+ "http://[::]:80"
44
+ end
38
45
 
39
- trap(SIGHUP, &self.method(:reload))
46
+ # The connection timeout to use for incoming connections.
47
+ def timeout
48
+ 10.0
49
+ end
50
+
51
+ # # The insecure endpoint for connecting to the {Redirect} instance.
52
+ # def insecure_endpoint(**options)
53
+ # Async::HTTP::Endpoint.parse(bind_insecure, **options)
54
+ # end
55
+
56
+ # # The secure endpoint for connecting to the {Proxy} instance.
57
+ # def secure_endpoint(**options)
58
+ # Async::HTTP::Endpoint.parse(bind_secure, **options)
59
+ # end
60
+
61
+ # # An endpoint suitable for connecting to the specified hostname.
62
+ # def host_endpoint(hostname, **options)
63
+ # endpoint = secure_endpoint(**options)
64
+
65
+ # url = URI.parse(bind_secure)
66
+ # url.hostname = hostname
67
+
68
+ # return Async::HTTP::Endpoint.new(url, hostname: endpoint.hostname)
69
+ # end
70
+ end
71
+
72
+ def self.included(target)
73
+ target.include(Environnment)
40
74
  end
41
75
 
42
76
  # Drop privileges according to the user and group of the specified path.
@@ -87,7 +121,9 @@ module Falcon
87
121
  end
88
122
 
89
123
  container.reload do
90
- @command.resolved_paths do |path|
124
+ evaluator = @environment.evaluator
125
+
126
+ evaluator.configuration_paths.each do |path|
91
127
  path = File.expand_path(path)
92
128
  root = File.dirname(path)
93
129
 
@@ -96,18 +132,18 @@ module Falcon
96
132
 
97
133
  container.spawn(name: "Falcon Redirector", restart: true, key: :redirect) do |instance|
98
134
  instance.exec(falcon_path, "redirect",
99
- "--bind", @command.bind_insecure,
100
- "--timeout", @command.timeout.to_s,
101
- "--redirect", @command.bind_secure,
102
- *@command.paths, ready: false
135
+ "--bind", evaluator.bind_insecure,
136
+ "--timeout", evaluator.timeout.to_s,
137
+ "--redirect", evaluator.bind_secure,
138
+ *evaluator.configuration_paths, ready: false
103
139
  )
104
140
  end
105
141
 
106
142
  container.spawn(name: "Falcon Proxy", restart: true, key: :proxy) do |instance|
107
143
  instance.exec(falcon_path, "proxy",
108
- "--bind", @command.bind_secure,
109
- "--timeout", @command.timeout.to_s,
110
- *@command.paths, ready: false
144
+ "--bind", evaluator.bind_secure,
145
+ "--timeout", evaluator.timeout.to_s,
146
+ *evaluator.configuration_paths, ready: false
111
147
  )
112
148
  end
113
149
  end
data/lib/falcon/tls.rb CHANGED
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2020-2023, by Samuel Williams.
22
5
 
23
6
  module Falcon
24
7
  module TLS
@@ -1,25 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2017-2024, by Samuel Williams.
22
5
 
23
6
  module Falcon
24
- VERSION = "0.42.3"
7
+ VERSION = "0.44.0"
25
8
  end
data/lib/falcon.rb CHANGED
@@ -1,23 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2017-2024, by Samuel Williams.
22
5
 
23
6
  require_relative "falcon/server"
7
+
8
+ # Falcon, running on Rails, requires specific configuration:
9
+ require_relative "falcon/railtie" if defined?(Rails::Railtie)
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Released under the MIT License.
4
+ # Copyright, 2017-2023, by Samuel Williams.
5
+ # Copyright, 2019, by Bryan Powell.
6
+
3
7
  require 'rack/handler'
4
8
 
5
9
  require_relative '../../falcon'