falcon 0.36.4 → 0.36.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/lib/falcon/adapters/early_hints.rb +8 -0
  3. data/lib/falcon/adapters/input.rb +32 -11
  4. data/lib/falcon/adapters/output.rb +20 -1
  5. data/lib/falcon/adapters/rack.rb +59 -32
  6. data/lib/falcon/adapters/response.rb +23 -1
  7. data/lib/falcon/adapters/rewindable.rb +10 -3
  8. data/lib/falcon/command.rb +2 -0
  9. data/lib/falcon/command/host.rb +13 -2
  10. data/lib/falcon/command/paths.rb +4 -0
  11. data/lib/falcon/command/proxy.rb +14 -0
  12. data/lib/falcon/command/redirect.rb +12 -0
  13. data/lib/falcon/command/serve.rb +22 -15
  14. data/lib/falcon/command/supervisor.rb +15 -1
  15. data/lib/falcon/command/top.rb +16 -0
  16. data/lib/falcon/command/virtual.rb +15 -0
  17. data/lib/falcon/configuration.rb +69 -7
  18. data/lib/falcon/controller/host.rb +12 -0
  19. data/lib/falcon/controller/proxy.rb +13 -0
  20. data/lib/falcon/controller/redirect.rb +7 -0
  21. data/lib/falcon/controller/serve.rb +14 -1
  22. data/lib/falcon/controller/virtual.rb +17 -0
  23. data/lib/falcon/endpoint.rb +8 -0
  24. data/lib/falcon/{configuration/proxy.rb → environments.rb} +9 -5
  25. data/lib/falcon/environments/application.rb +68 -0
  26. data/lib/falcon/{configuration/application.rb → environments/lets_encrypt_tls.rb} +21 -20
  27. data/lib/falcon/{configuration/lets_encrypt_tls.rb → environments/proxy.rb} +13 -6
  28. data/lib/falcon/{configuration → environments}/rack.rb +14 -2
  29. data/lib/falcon/{configuration → environments}/self_signed_tls.rb +9 -1
  30. data/lib/falcon/{configuration → environments}/supervisor.rb +19 -5
  31. data/lib/falcon/{configuration → environments}/tls.rb +39 -5
  32. data/lib/falcon/extensions/openssl.rb +1 -0
  33. data/lib/falcon/middleware/proxy.rb +26 -5
  34. data/lib/falcon/middleware/redirect.rb +11 -0
  35. data/lib/falcon/{verbose.rb → middleware/verbose.rb} +34 -26
  36. data/lib/falcon/proxy_endpoint.rb +21 -0
  37. data/lib/falcon/server.rb +8 -2
  38. data/lib/falcon/service/application.rb +9 -0
  39. data/lib/falcon/service/generic.rb +18 -0
  40. data/lib/falcon/service/proxy.rb +6 -0
  41. data/lib/falcon/service/supervisor.rb +13 -1
  42. data/lib/falcon/services.rb +21 -0
  43. data/lib/falcon/tls.rb +4 -2
  44. data/lib/falcon/version.rb +1 -1
  45. data/lib/rack/handler/falcon.rb +7 -1
  46. metadata +16 -72
  47. data/.editorconfig +0 -5
  48. data/.github/FUNDING.yml +0 -3
  49. data/.github/workflows/development.yml +0 -60
  50. data/.gitignore +0 -14
  51. data/.rspec +0 -3
  52. data/Gemfile +0 -17
  53. data/README.md +0 -316
  54. data/examples/beer/config.ru +0 -57
  55. data/examples/beer/falcon.rb +0 -8
  56. data/examples/benchmark/config.ru +0 -39
  57. data/examples/benchmark/falcon.rb +0 -6
  58. data/examples/csv/config.ru +0 -31
  59. data/examples/google/falcon.rb +0 -14
  60. data/examples/hello/config.ru +0 -22
  61. data/examples/hello/falcon.rb +0 -24
  62. data/examples/hello/preload.rb +0 -7
  63. data/examples/internet/config.ru +0 -54
  64. data/examples/memory/allocations.rb +0 -39
  65. data/examples/memory/config.ru +0 -14
  66. data/examples/push/client.rb +0 -29
  67. data/examples/push/config.ru +0 -28
  68. data/examples/push/index.html +0 -14
  69. data/examples/push/script.js +0 -2
  70. data/examples/push/style.css +0 -4
  71. data/examples/redis/Gemfile +0 -9
  72. data/examples/redis/config.ru +0 -28
  73. data/examples/sequel/Gemfile +0 -4
  74. data/examples/sequel/config.ru +0 -8
  75. data/examples/sequel/data.sqlite3 +0 -0
  76. data/examples/server/standalone.rb +0 -27
  77. data/examples/sinatra/Gemfile +0 -7
  78. data/examples/sinatra/Gemfile.lock +0 -53
  79. data/examples/sinatra/config.ru +0 -16
  80. data/examples/trailers/config.ru +0 -34
  81. data/examples/trailers/falcon.rb +0 -8
  82. data/falcon.gemspec +0 -45
  83. data/gems/rack1.gemfile +0 -4
  84. data/gems/rack3.gemfile +0 -4
  85. data/logo-square.afdesign +0 -0
  86. data/logo.afdesign +0 -0
  87. data/logo.svg +0 -107
  88. data/server.rb +0 -21
  89. data/tasks/benchmark.rake +0 -103
@@ -22,7 +22,13 @@
22
22
 
23
23
  module Falcon
24
24
  module Service
25
+ # Captures the stateful behaviour of a specific service.
26
+ # Specifies the interfaces required by derived classes.
27
+ #
28
+ # Designed to be invoked within an {Async::Controller::Container}.
25
29
  class Generic
30
+ # Convert the given environment into a service if possible.
31
+ # @parameter environment [Build::Environment] The environment to use to construct the service.
26
32
  def self.wrap(environment)
27
33
  evaluator = environment.evaluator
28
34
  service = evaluator.service || self
@@ -30,29 +36,41 @@ module Falcon
30
36
  return service.new(environment)
31
37
  end
32
38
 
39
+ # Initialize the service from the given environment.
40
+ # @parameter environment [Build::Environment]
33
41
  def initialize(environment)
34
42
  @environment = environment
35
43
  @evaluator = @environment.evaluator
36
44
  end
37
45
 
46
+ # Whether the service environment contains the specified keys.
47
+ # This is used for matching environment configuration to service behaviour.
38
48
  def include?(keys)
39
49
  keys.all?{|key| @environment.include?(key)}
40
50
  end
41
51
 
52
+ # The name of the service.
53
+ # e.g. `myapp.com`.
42
54
  def name
43
55
  @evaluator.name
44
56
  end
45
57
 
58
+ # The logger to use for this service.
59
+ # @returns [Console::Logger]
46
60
  def logger
47
61
  return Async.logger # .with(name: name)
48
62
  end
49
63
 
64
+ # Start the service.
50
65
  def start
51
66
  end
52
67
 
68
+ # Setup the service into the specified container.
69
+ # @parameter container [Async::Container::Generic]
53
70
  def setup(container)
54
71
  end
55
72
 
73
+ # Stop the service.
56
74
  def stop
57
75
  end
58
76
  end
@@ -32,26 +32,32 @@ module Falcon
32
32
  "#{self.class} for #{self.authority}"
33
33
  end
34
34
 
35
+ # The host that this proxy will receive connections for.
35
36
  def authority
36
37
  @evaluator.authority
37
38
  end
38
39
 
40
+ # The upstream endpoint that this proxy will connect to.
39
41
  def endpoint
40
42
  @evaluator.endpoint
41
43
  end
42
44
 
45
+ # The {OpenSSL::SSL::SSLContext} that will be used for incoming connections.
43
46
  def ssl_context
44
47
  @evaluator.ssl_context
45
48
  end
46
49
 
50
+ # The root
47
51
  def root
48
52
  @evaluator.root
49
53
  end
50
54
 
55
+ # The protocol this proxy will use to talk to the upstream host.
51
56
  def protocol
52
57
  endpoint.protocol
53
58
  end
54
59
 
60
+ # The scheme this proxy will use to talk to the upstream host.
55
61
  def scheme
56
62
  endpoint.scheme
57
63
  end
@@ -28,33 +28,41 @@ require 'async/io/shared_endpoint'
28
28
 
29
29
  module Falcon
30
30
  module Service
31
+ # Implements a host supervisor which can restart the host services and provide various metrics about the running processes.
31
32
  class Supervisor < Generic
33
+ # Initialize the supervisor using the given environment.
34
+ # @parameter environment [Build::Environment]
32
35
  def initialize(environment)
33
36
  super
34
37
 
35
38
  @bound_endpoint = nil
36
39
  end
37
40
 
41
+ # The endpoint which the supervisor will bind to.
42
+ # Typically a unix pipe in the same directory as the host.
38
43
  def endpoint
39
44
  @evaluator.endpoint
40
45
  end
41
46
 
47
+ # Restart the process group that the supervisor belongs to.
42
48
  def do_restart(message)
43
49
  # Tell the parent of this process group to spin up a new process group/container.
44
50
  # Wait for that to start accepting new connections.
45
51
  # Stop accepting connections.
46
52
  # Wait for existing connnections to drain.
47
53
  # Terminate this process group.
48
-
49
54
  signal = message[:signal] || :INT
50
55
 
51
56
  Process.kill(signal, Process.ppid)
52
57
  end
53
58
 
59
+ # Capture process metrics relating to the process group that the supervisor belongs to.
54
60
  def do_metrics(message)
55
61
  Process::Metrics::General.capture(pid: Process.ppid, ppid: Process.ppid)
56
62
  end
57
63
 
64
+ # Handle an incoming request.
65
+ # @parameter message [Hash] The decoded message.
58
66
  def handle(message)
59
67
  case message[:please]
60
68
  when 'restart'
@@ -64,6 +72,7 @@ module Falcon
64
72
  end
65
73
  end
66
74
 
75
+ # Bind the supervisor to the specified endpoint.
67
76
  def start
68
77
  Async.logger.info(self) {"Binding to #{self.endpoint}..."}
69
78
 
@@ -74,6 +83,8 @@ module Falcon
74
83
  super
75
84
  end
76
85
 
86
+ # Start the supervisor process which accepts connections from the bound endpoint and processes JSON formatted messages.
87
+ # @parameter container [Async::Container::Generic]
77
88
  def setup(container)
78
89
  container.run(name: self.name, restart: true, count: 1) do |instance|
79
90
  Async do
@@ -93,6 +104,7 @@ module Falcon
93
104
  super
94
105
  end
95
106
 
107
+ # Release the bound endpoint.
96
108
  def stop
97
109
  @bound_endpoint&.close
98
110
  @bound_endpoint = nil
@@ -23,7 +23,19 @@
23
23
  require_relative 'service/generic'
24
24
 
25
25
  module Falcon
26
+ # Represents one or more services associated with a host.
27
+ #
28
+ # The services model allows falcon to manage one more more service associated with a given host. Some examples of services include:
29
+ #
30
+ # - Rack applications wrapped by {Service::Application}.
31
+ # - Host supervisor implemented in {Service::Supervisor}.
32
+ # - Proxy services wrapped by {Service::Proxy}.
33
+ #
34
+ # The list of services is typically generated from the user supplied `falcon.rb` configuration file, which is loaded into an immutable {Configuration} instance, which is mapped into a list of services.
26
35
  class Services
36
+ # Initialize the services from the given configuration.
37
+ #
38
+ # @parameter configuration [Configuration]
27
39
  def initialize(configuration)
28
40
  @named = {}
29
41
 
@@ -34,14 +46,19 @@ module Falcon
34
46
  end
35
47
  end
36
48
 
49
+ # Enumerate all named services.
37
50
  def each(&block)
38
51
  @named.each_value(&block)
39
52
  end
40
53
 
54
+ # Add a named service.
55
+ #
56
+ # @parameter service [Service]
41
57
  def add(service)
42
58
  @named[service.name] = service
43
59
  end
44
60
 
61
+ # Start all named services.
45
62
  def start
46
63
  @named.each do |name, service|
47
64
  Async.logger.debug(self) {"Starting #{name}..."}
@@ -49,6 +66,9 @@ module Falcon
49
66
  end
50
67
  end
51
68
 
69
+ # Setup all named services into the given container.
70
+ #
71
+ # @parameter container [Async::Container::Generic]
52
72
  def setup(container)
53
73
  @named.each do |name, service|
54
74
  Async.logger.debug(self) {"Setup #{name} into #{container}..."}
@@ -58,6 +78,7 @@ module Falcon
58
78
  return container
59
79
  end
60
80
 
81
+ # Stop all named services.
61
82
  def stop
62
83
  failed = false
63
84
 
@@ -24,8 +24,10 @@ require_relative 'extensions/openssl'
24
24
 
25
25
  module Falcon
26
26
  module TLS
27
- # We follow "Intermediate compatibility"
28
- # https://wiki.mozilla.org/Security/Server_Side_TLS
27
+ # The list of supported ciphers.
28
+ #
29
+ # We follow "Intermediate compatibility" as oulined here:
30
+ # <https://wiki.mozilla.org/Security/Server_Side_TLS>
29
31
  SERVER_CIPHERS = [
30
32
  # TLS 1.3:
31
33
  "TLS_AES_128_GCM_SHA256",
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Falcon
24
- VERSION = "0.36.4"
24
+ VERSION = "0.36.5"
25
25
  end
@@ -9,10 +9,14 @@ require 'async/io/host_endpoint'
9
9
 
10
10
  module Rack
11
11
  module Handler
12
+ # The falcon adaptor for the `rackup` executable.
12
13
  module Falcon
13
- SCHEME = "http".freeze
14
+ # The default scheme.
15
+ SCHEME = "http"
14
16
  NAME = :falcon
15
17
 
18
+ # Generate an endpoint for the given `rackup` options.
19
+ # @returns [Async::IO::Endpoint]
16
20
  def self.endpoint_for(**options)
17
21
  host = options[:Host] || 'localhost'
18
22
  port = Integer(options[:Port] || 9292)
@@ -20,6 +24,8 @@ module Rack
20
24
  return Async::IO::Endpoint.tcp(host, port)
21
25
  end
22
26
 
27
+ # Run the specified app using the given options:
28
+ # @parameter app [Object] The rack middleware.
23
29
  def self.run(app, **options)
24
30
  endpoint = endpoint_for(**options)
25
31
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: falcon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.36.4
4
+ version: 0.36.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-25 00:00:00.000000000 Z
11
+ date: 2020-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -248,21 +248,7 @@ dependencies:
248
248
  - - "~>"
249
249
  - !ruby/object:Gem::Version
250
250
  version: '3.6'
251
- - !ruby/object:Gem::Dependency
252
- name: bake-bundler
253
- requirement: !ruby/object:Gem::Requirement
254
- requirements:
255
- - - ">="
256
- - !ruby/object:Gem::Version
257
- version: '0'
258
- type: :development
259
- prerelease: false
260
- version_requirements: !ruby/object:Gem::Requirement
261
- requirements:
262
- - - ">="
263
- - !ruby/object:Gem::Version
264
- version: '0'
265
- description:
251
+ description:
266
252
  email:
267
253
  - samuel.williams@oriontransfer.co.nz
268
254
  executables:
@@ -271,47 +257,9 @@ executables:
271
257
  extensions: []
272
258
  extra_rdoc_files: []
273
259
  files:
274
- - ".editorconfig"
275
- - ".github/FUNDING.yml"
276
- - ".github/workflows/development.yml"
277
- - ".gitignore"
278
- - ".rspec"
279
- - Gemfile
280
- - README.md
281
260
  - bake/falcon/supervisor.rb
282
261
  - bin/falcon
283
262
  - bin/falcon-host
284
- - examples/beer/config.ru
285
- - examples/beer/falcon.rb
286
- - examples/benchmark/config.ru
287
- - examples/benchmark/falcon.rb
288
- - examples/csv/config.ru
289
- - examples/google/falcon.rb
290
- - examples/hello/config.ru
291
- - examples/hello/falcon.rb
292
- - examples/hello/preload.rb
293
- - examples/internet/config.ru
294
- - examples/memory/allocations.rb
295
- - examples/memory/config.ru
296
- - examples/push/client.rb
297
- - examples/push/config.ru
298
- - examples/push/index.html
299
- - examples/push/script.js
300
- - examples/push/style.css
301
- - examples/redis/Gemfile
302
- - examples/redis/config.ru
303
- - examples/sequel/Gemfile
304
- - examples/sequel/config.ru
305
- - examples/sequel/data.sqlite3
306
- - examples/server/standalone.rb
307
- - examples/sinatra/Gemfile
308
- - examples/sinatra/Gemfile.lock
309
- - examples/sinatra/config.ru
310
- - examples/trailers/config.ru
311
- - examples/trailers/falcon.rb
312
- - falcon.gemspec
313
- - gems/rack1.gemfile
314
- - gems/rack3.gemfile
315
263
  - lib/falcon.rb
316
264
  - lib/falcon/adapters/early_hints.rb
317
265
  - lib/falcon/adapters/input.rb
@@ -329,22 +277,24 @@ files:
329
277
  - lib/falcon/command/top.rb
330
278
  - lib/falcon/command/virtual.rb
331
279
  - lib/falcon/configuration.rb
332
- - lib/falcon/configuration/application.rb
333
- - lib/falcon/configuration/lets_encrypt_tls.rb
334
- - lib/falcon/configuration/proxy.rb
335
- - lib/falcon/configuration/rack.rb
336
- - lib/falcon/configuration/self_signed_tls.rb
337
- - lib/falcon/configuration/supervisor.rb
338
- - lib/falcon/configuration/tls.rb
339
280
  - lib/falcon/controller/host.rb
340
281
  - lib/falcon/controller/proxy.rb
341
282
  - lib/falcon/controller/redirect.rb
342
283
  - lib/falcon/controller/serve.rb
343
284
  - lib/falcon/controller/virtual.rb
344
285
  - lib/falcon/endpoint.rb
286
+ - lib/falcon/environments.rb
287
+ - lib/falcon/environments/application.rb
288
+ - lib/falcon/environments/lets_encrypt_tls.rb
289
+ - lib/falcon/environments/proxy.rb
290
+ - lib/falcon/environments/rack.rb
291
+ - lib/falcon/environments/self_signed_tls.rb
292
+ - lib/falcon/environments/supervisor.rb
293
+ - lib/falcon/environments/tls.rb
345
294
  - lib/falcon/extensions/openssl.rb
346
295
  - lib/falcon/middleware/proxy.rb
347
296
  - lib/falcon/middleware/redirect.rb
297
+ - lib/falcon/middleware/verbose.rb
348
298
  - lib/falcon/proxy_endpoint.rb
349
299
  - lib/falcon/server.rb
350
300
  - lib/falcon/service/application.rb
@@ -353,18 +303,12 @@ files:
353
303
  - lib/falcon/service/supervisor.rb
354
304
  - lib/falcon/services.rb
355
305
  - lib/falcon/tls.rb
356
- - lib/falcon/verbose.rb
357
306
  - lib/falcon/version.rb
358
307
  - lib/rack/handler/falcon.rb
359
- - logo-square.afdesign
360
- - logo.afdesign
361
- - logo.svg
362
- - server.rb
363
- - tasks/benchmark.rake
364
308
  homepage: https://github.com/socketry/falcon
365
309
  licenses: []
366
310
  metadata: {}
367
- post_install_message:
311
+ post_install_message:
368
312
  rdoc_options: []
369
313
  require_paths:
370
314
  - lib
@@ -372,7 +316,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
372
316
  requirements:
373
317
  - - "~>"
374
318
  - !ruby/object:Gem::Version
375
- version: '2.4'
319
+ version: '2.5'
376
320
  required_rubygems_version: !ruby/object:Gem::Requirement
377
321
  requirements:
378
322
  - - ">="
@@ -380,7 +324,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
380
324
  version: '0'
381
325
  requirements: []
382
326
  rubygems_version: 3.1.2
383
- signing_key:
327
+ signing_key:
384
328
  specification_version: 4
385
329
  summary: A fast, asynchronous, rack-compatible web server.
386
330
  test_files: []
@@ -1,5 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- indent_style = tab
5
- indent_size = 2
@@ -1,3 +0,0 @@
1
- # These are supported funding model platforms
2
- custom: https://github.com/socketry/community/#funding
3
- github: ioquatix
@@ -1,60 +0,0 @@
1
- name: Development
2
-
3
- on: [push, pull_request]
4
-
5
- jobs:
6
- test:
7
- runs-on: ${{matrix.os}}-latest
8
- continue-on-error: ${{matrix.experimental}}
9
-
10
- strategy:
11
- matrix:
12
- experimental: [false]
13
-
14
- os:
15
- - ubuntu
16
- - macos
17
-
18
- ruby:
19
- - 2.5
20
- - 2.6
21
- - 2.7
22
-
23
- include:
24
- # - experimental: true
25
- # os: ubuntu
26
- # ruby: truffleruby
27
- # - experimental: true
28
- # os: ubuntu
29
- # ruby: jruby
30
- - experimental: true
31
- os: ubuntu
32
- ruby: head
33
- - experimental: true
34
- os: ubuntu
35
- ruby: 2.7
36
- env: BUNDLE_GEMFILE=gems/rack1.gemfile
37
- - experimental: true
38
- os: ubuntu
39
- ruby: 2.7
40
- env: BUNDLE_GEMFILE=gems/rack3.gemfile
41
- - experimental: true
42
- os: ubuntu
43
- ruby: 2.6
44
- env: COVERAGE=PartialSummary,Coveralls
45
-
46
- steps:
47
- - uses: actions/checkout@v1
48
- - uses: ruby/setup-ruby@v1
49
- with:
50
- ruby-version: ${{matrix.ruby}}
51
-
52
- - name: Installing packages (ubuntu)
53
- if: matrix.os == 'ubuntu'
54
- run: sudo apt-get install apache2-utils
55
-
56
- - name: Install dependencies
57
- run: ${{matrix.env}} bundle install
58
-
59
- - name: Run tests
60
- run: ${{matrix.env}} bundle exec rspec