falcon 0.36.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +5 -0
- data/.github/FUNDING.yml +3 -0
- data/.github/workflows/development.yml +60 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/Gemfile +17 -0
- data/README.md +316 -0
- data/bake/falcon/supervisor.rb +8 -0
- data/bin/falcon +32 -0
- data/bin/falcon-host +28 -0
- data/examples/beer/config.ru +57 -0
- data/examples/beer/falcon.rb +8 -0
- data/examples/benchmark/config.ru +39 -0
- data/examples/benchmark/falcon.rb +6 -0
- data/examples/csv/config.ru +31 -0
- data/examples/google/falcon.rb +14 -0
- data/examples/hello/config.ru +22 -0
- data/examples/hello/falcon.rb +24 -0
- data/examples/hello/preload.rb +7 -0
- data/examples/internet/config.ru +54 -0
- data/examples/memory/allocations.rb +39 -0
- data/examples/memory/config.ru +14 -0
- data/examples/push/client.rb +29 -0
- data/examples/push/config.ru +28 -0
- data/examples/push/index.html +14 -0
- data/examples/push/script.js +2 -0
- data/examples/push/style.css +4 -0
- data/examples/redis/Gemfile +9 -0
- data/examples/redis/config.ru +28 -0
- data/examples/sequel/Gemfile +4 -0
- data/examples/sequel/config.ru +8 -0
- data/examples/sequel/data.sqlite3 +0 -0
- data/examples/server/standalone.rb +27 -0
- data/examples/sinatra/Gemfile +7 -0
- data/examples/sinatra/Gemfile.lock +53 -0
- data/examples/sinatra/config.ru +16 -0
- data/examples/trailers/config.ru +34 -0
- data/examples/trailers/falcon.rb +8 -0
- data/falcon.gemspec +45 -0
- data/gems/rack1.gemfile +4 -0
- data/gems/rack3.gemfile +4 -0
- data/lib/falcon.rb +23 -0
- data/lib/falcon/adapters/early_hints.rb +49 -0
- data/lib/falcon/adapters/input.rb +131 -0
- data/lib/falcon/adapters/output.rb +101 -0
- data/lib/falcon/adapters/rack.rb +202 -0
- data/lib/falcon/adapters/response.rb +91 -0
- data/lib/falcon/adapters/rewindable.rb +67 -0
- data/lib/falcon/command.rb +31 -0
- data/lib/falcon/command/host.rb +69 -0
- data/lib/falcon/command/paths.rb +47 -0
- data/lib/falcon/command/proxy.rb +71 -0
- data/lib/falcon/command/redirect.rb +76 -0
- data/lib/falcon/command/serve.rb +151 -0
- data/lib/falcon/command/supervisor.rb +78 -0
- data/lib/falcon/command/top.rb +94 -0
- data/lib/falcon/command/virtual.rb +89 -0
- data/lib/falcon/configuration.rb +147 -0
- data/lib/falcon/configuration/application.rb +46 -0
- data/lib/falcon/configuration/lets_encrypt_tls.rb +30 -0
- data/lib/falcon/configuration/proxy.rb +27 -0
- data/lib/falcon/configuration/rack.rb +38 -0
- data/lib/falcon/configuration/self_signed_tls.rb +47 -0
- data/lib/falcon/configuration/supervisor.rb +37 -0
- data/lib/falcon/configuration/tls.rb +70 -0
- data/lib/falcon/controller/host.rb +60 -0
- data/lib/falcon/controller/proxy.rb +109 -0
- data/lib/falcon/controller/redirect.rb +69 -0
- data/lib/falcon/controller/serve.rb +111 -0
- data/lib/falcon/controller/virtual.rb +100 -0
- data/lib/falcon/endpoint.rb +52 -0
- data/lib/falcon/extensions/openssl.rb +33 -0
- data/lib/falcon/middleware/proxy.rb +145 -0
- data/lib/falcon/middleware/redirect.rb +66 -0
- data/lib/falcon/proxy_endpoint.rb +71 -0
- data/lib/falcon/server.rb +54 -0
- data/lib/falcon/service/application.rb +93 -0
- data/lib/falcon/service/generic.rb +60 -0
- data/lib/falcon/service/proxy.rb +60 -0
- data/lib/falcon/service/supervisor.rb +104 -0
- data/lib/falcon/services.rb +78 -0
- data/lib/falcon/tls.rb +46 -0
- data/lib/falcon/verbose.rb +59 -0
- data/lib/falcon/version.rb +25 -0
- data/lib/rack/handler/falcon.rb +40 -0
- data/logo-square.afdesign +0 -0
- data/logo.afdesign +0 -0
- data/logo.svg +107 -0
- data/server.rb +21 -0
- data/tasks/benchmark.rake +103 -0
- metadata +386 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright, 2019, 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.
|
22
|
+
|
23
|
+
load(:tls)
|
24
|
+
|
25
|
+
add(:lets_encrypt_tls, :tls) do
|
26
|
+
lets_encrypt_root '/etc/letsencrypt/live'
|
27
|
+
|
28
|
+
ssl_certificate_path {File.join(lets_encrypt_root, authority, "fullchain.pem")}
|
29
|
+
ssl_private_key_path {File.join(lets_encrypt_root, authority, "privkey.pem")}
|
30
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright, 2019, 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.
|
22
|
+
|
23
|
+
add(:proxy) do
|
24
|
+
endpoint {::Async::HTTP::Endpoint.parse(url)}
|
25
|
+
|
26
|
+
service ::Falcon::Service::Proxy
|
27
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright, 2019, 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.
|
22
|
+
|
23
|
+
load :application
|
24
|
+
|
25
|
+
add(:rack, :application) do
|
26
|
+
config_path {::File.expand_path("config.ru", root)}
|
27
|
+
|
28
|
+
cache false
|
29
|
+
|
30
|
+
middleware do
|
31
|
+
app, _ = ::Rack::Builder.parse_file(config_path)
|
32
|
+
|
33
|
+
::Falcon::Server.middleware(app,
|
34
|
+
verbose: verbose,
|
35
|
+
cache: cache
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright, 2019, 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.
|
22
|
+
|
23
|
+
require 'localhost/authority'
|
24
|
+
|
25
|
+
add(:self_signed_tls) do
|
26
|
+
ssl_session_id {"falcon"}
|
27
|
+
|
28
|
+
ssl_context do
|
29
|
+
contexts = Localhost::Authority.fetch(authority)
|
30
|
+
|
31
|
+
contexts.server_context.tap do |context|
|
32
|
+
context.alpn_select_cb = lambda do |protocols|
|
33
|
+
if protocols.include? "h2"
|
34
|
+
return "h2"
|
35
|
+
elsif protocols.include? "http/1.1"
|
36
|
+
return "http/1.1"
|
37
|
+
elsif protocols.include? "http/1.0"
|
38
|
+
return "http/1.0"
|
39
|
+
else
|
40
|
+
return nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context.session_id_context = ssl_session_id
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright, 2019, 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.
|
22
|
+
|
23
|
+
require_relative '../service/supervisor'
|
24
|
+
|
25
|
+
add(:supervisor) do
|
26
|
+
start true
|
27
|
+
|
28
|
+
name "supervisor"
|
29
|
+
|
30
|
+
ipc_path {::File.expand_path("supervisor.ipc", root)}
|
31
|
+
|
32
|
+
endpoint {Async::IO::Endpoint.unix(ipc_path)}
|
33
|
+
|
34
|
+
service do
|
35
|
+
::Falcon::Service::Supervisor
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright, 2019, 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.
|
22
|
+
|
23
|
+
require_relative '../extensions/openssl'
|
24
|
+
require_relative '../controller/proxy'
|
25
|
+
require_relative '../tls'
|
26
|
+
|
27
|
+
add(:tls) do
|
28
|
+
ssl_session_id "falcon"
|
29
|
+
ssl_ciphers Falcon::TLS::SERVER_CIPHERS
|
30
|
+
|
31
|
+
ssl_certificate_path {File.expand_path("ssl/certificate.pem", root)}
|
32
|
+
ssl_certificates {OpenSSL::X509.load_certificates(ssl_certificate_path)}
|
33
|
+
|
34
|
+
ssl_certificate {ssl_certificates[0]}
|
35
|
+
ssl_certificate_chain {ssl_certificates[1..-1]}
|
36
|
+
|
37
|
+
ssl_private_key_path {File.expand_path("ssl/private.key", root)}
|
38
|
+
ssl_private_key {OpenSSL::PKey::RSA.new(File.read(ssl_private_key_path))}
|
39
|
+
|
40
|
+
ssl_context do
|
41
|
+
OpenSSL::SSL::SSLContext.new.tap do |context|
|
42
|
+
context.add_certificate(ssl_certificate, ssl_private_key, ssl_certificate_chain)
|
43
|
+
|
44
|
+
context.session_cache_mode = OpenSSL::SSL::SSLContext::SESSION_CACHE_CLIENT
|
45
|
+
context.session_id_context = ssl_session_id
|
46
|
+
|
47
|
+
context.alpn_select_cb = lambda do |protocols|
|
48
|
+
if protocols.include? "h2"
|
49
|
+
return "h2"
|
50
|
+
elsif protocols.include? "http/1.1"
|
51
|
+
return "http/1.1"
|
52
|
+
elsif protocols.include? "http/1.0"
|
53
|
+
return "http/1.0"
|
54
|
+
else
|
55
|
+
return nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# TODO Ruby 2.4 requires using ssl_version.
|
60
|
+
context.ssl_version = :TLSv1_2_server
|
61
|
+
|
62
|
+
context.set_params(
|
63
|
+
ciphers: ssl_ciphers,
|
64
|
+
verify_mode: OpenSSL::SSL::VERIFY_NONE,
|
65
|
+
)
|
66
|
+
|
67
|
+
context.setup
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright, 2019, 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.
|
22
|
+
|
23
|
+
require_relative '../services'
|
24
|
+
|
25
|
+
require 'async/container/controller'
|
26
|
+
|
27
|
+
module Falcon
|
28
|
+
module Controller
|
29
|
+
class Host < Async::Container::Controller
|
30
|
+
def initialize(command, **options)
|
31
|
+
@command = command
|
32
|
+
|
33
|
+
@configuration = command.configuration
|
34
|
+
@services = Services.new(@configuration)
|
35
|
+
|
36
|
+
super(**options)
|
37
|
+
end
|
38
|
+
|
39
|
+
def create_container
|
40
|
+
@command.container_class.new
|
41
|
+
end
|
42
|
+
|
43
|
+
def start
|
44
|
+
@services.start
|
45
|
+
|
46
|
+
super
|
47
|
+
end
|
48
|
+
|
49
|
+
def setup(container)
|
50
|
+
@services.setup(container)
|
51
|
+
end
|
52
|
+
|
53
|
+
def stop(*)
|
54
|
+
@services.stop
|
55
|
+
|
56
|
+
super
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
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.
|
22
|
+
|
23
|
+
require 'async/container/controller'
|
24
|
+
|
25
|
+
require_relative 'serve'
|
26
|
+
require_relative '../middleware/proxy'
|
27
|
+
require_relative '../service/proxy'
|
28
|
+
|
29
|
+
require_relative '../tls'
|
30
|
+
|
31
|
+
module Falcon
|
32
|
+
module Controller
|
33
|
+
class Proxy < Serve
|
34
|
+
DEFAULT_SESSION_ID = "falcon"
|
35
|
+
|
36
|
+
def initialize(command, session_id: DEFAULT_SESSION_ID, **options)
|
37
|
+
super(command, **options)
|
38
|
+
|
39
|
+
@session_id = session_id
|
40
|
+
@hosts = {}
|
41
|
+
end
|
42
|
+
|
43
|
+
def load_app
|
44
|
+
return Middleware::Proxy.new(Middleware::BadRequest, @hosts)
|
45
|
+
end
|
46
|
+
|
47
|
+
def name
|
48
|
+
"Falcon Proxy Server"
|
49
|
+
end
|
50
|
+
|
51
|
+
def host_context(socket, hostname)
|
52
|
+
if host = @hosts[hostname]
|
53
|
+
Async.logger.debug(self) {"Resolving #{hostname} -> #{host}"}
|
54
|
+
|
55
|
+
socket.hostname = hostname
|
56
|
+
|
57
|
+
return host.ssl_context
|
58
|
+
else
|
59
|
+
Async.logger.warn(self) {"Unable to resolve #{hostname}!"}
|
60
|
+
|
61
|
+
return nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def ssl_context
|
66
|
+
@server_context ||= OpenSSL::SSL::SSLContext.new.tap do |context|
|
67
|
+
context.servername_cb = Proc.new do |socket, hostname|
|
68
|
+
self.host_context(socket, hostname)
|
69
|
+
end
|
70
|
+
|
71
|
+
context.session_id_context = @session_id
|
72
|
+
|
73
|
+
context.ssl_version = :TLSv1_2_server
|
74
|
+
|
75
|
+
context.set_params(
|
76
|
+
ciphers: TLS::SERVER_CIPHERS,
|
77
|
+
verify_mode: OpenSSL::SSL::VERIFY_NONE,
|
78
|
+
)
|
79
|
+
|
80
|
+
context.setup
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def endpoint
|
85
|
+
@command.endpoint.with(
|
86
|
+
ssl_context: self.ssl_context,
|
87
|
+
reuse_address: true,
|
88
|
+
)
|
89
|
+
end
|
90
|
+
|
91
|
+
def start
|
92
|
+
configuration = @command.configuration
|
93
|
+
|
94
|
+
services = Services.new(configuration)
|
95
|
+
|
96
|
+
@hosts = {}
|
97
|
+
|
98
|
+
services.each do |service|
|
99
|
+
if service.is_a?(Service::Proxy)
|
100
|
+
Async.logger.info(self) {"Proxying #{service.authority} to #{service.endpoint}"}
|
101
|
+
@hosts[service.authority] = service
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
super
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
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.
|
22
|
+
|
23
|
+
require 'async/container/controller'
|
24
|
+
|
25
|
+
require_relative 'serve'
|
26
|
+
require_relative '../middleware/redirect'
|
27
|
+
require_relative '../service/proxy'
|
28
|
+
|
29
|
+
module Falcon
|
30
|
+
module Controller
|
31
|
+
class Redirect < Serve
|
32
|
+
def initialize(command, **options)
|
33
|
+
super(command, **options)
|
34
|
+
|
35
|
+
@hosts = {}
|
36
|
+
end
|
37
|
+
|
38
|
+
def load_app
|
39
|
+
return Middleware::Redirect.new(Middleware::NotFound, @hosts, @command.redirect_endpoint)
|
40
|
+
end
|
41
|
+
|
42
|
+
def name
|
43
|
+
"Falcon Redirect Server"
|
44
|
+
end
|
45
|
+
|
46
|
+
def endpoint
|
47
|
+
@command.endpoint.with(
|
48
|
+
reuse_address: true,
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
def start
|
53
|
+
configuration = @command.configuration
|
54
|
+
|
55
|
+
services = Services.new(configuration)
|
56
|
+
|
57
|
+
@hosts = {}
|
58
|
+
|
59
|
+
services.each do |service|
|
60
|
+
if service.is_a?(Service::Proxy)
|
61
|
+
@hosts[service.authority] = service
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
super
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|