falcon 0.36.0 → 0.36.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) 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 +17 -1
  12. data/lib/falcon/command/redirect.rb +15 -1
  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 +21 -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 +28 -2
  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 +14 -2
  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 +20 -77
  47. data/.editorconfig +0 -5
  48. data/.github/FUNDING.yml +0 -3
  49. data/.github/workflows/development.yml +0 -45
  50. data/.gitignore +0 -14
  51. data/.rspec +0 -3
  52. data/.travis.yml +0 -41
  53. data/Gemfile +0 -16
  54. data/README.md +0 -316
  55. data/examples/beer/config.ru +0 -57
  56. data/examples/beer/falcon.rb +0 -8
  57. data/examples/benchmark/config.ru +0 -39
  58. data/examples/benchmark/falcon.rb +0 -6
  59. data/examples/csv/config.ru +0 -31
  60. data/examples/google/falcon.rb +0 -14
  61. data/examples/hello/config.ru +0 -22
  62. data/examples/hello/falcon.rb +0 -24
  63. data/examples/hello/preload.rb +0 -7
  64. data/examples/internet/config.ru +0 -54
  65. data/examples/memory/allocations.rb +0 -39
  66. data/examples/memory/config.ru +0 -14
  67. data/examples/push/client.rb +0 -29
  68. data/examples/push/config.ru +0 -28
  69. data/examples/push/index.html +0 -14
  70. data/examples/push/script.js +0 -2
  71. data/examples/push/style.css +0 -4
  72. data/examples/redis/Gemfile +0 -9
  73. data/examples/redis/config.ru +0 -28
  74. data/examples/sequel/Gemfile +0 -4
  75. data/examples/sequel/config.ru +0 -8
  76. data/examples/sequel/data.sqlite3 +0 -0
  77. data/examples/server/standalone.rb +0 -27
  78. data/examples/sinatra/Gemfile +0 -7
  79. data/examples/sinatra/Gemfile.lock +0 -53
  80. data/examples/sinatra/config.ru +0 -16
  81. data/examples/trailers/config.ru +0 -34
  82. data/examples/trailers/falcon.rb +0 -8
  83. data/falcon.gemspec +0 -45
  84. data/gems/rack1.gemfile +0 -4
  85. data/gems/rack3.gemfile +0 -4
  86. data/logo-square.afdesign +0 -0
  87. data/logo.afdesign +0 -0
  88. data/logo.svg +0 -107
  89. data/server.rb +0 -21
  90. 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
- Process::Metrics.capture(pid: Process.ppid, ppid: Process.ppid)
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.0"
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.0
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-08 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
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.51.0
47
+ version: 0.52.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.51.0
54
+ version: 0.52.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: async-http-cache
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 0.1.0
145
+ version: 0.2.0
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 0.1.0
152
+ version: 0.2.0
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: async-rspec
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -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,48 +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
- - ".travis.yml"
280
- - Gemfile
281
- - README.md
282
260
  - bake/falcon/supervisor.rb
283
261
  - bin/falcon
284
262
  - bin/falcon-host
285
- - examples/beer/config.ru
286
- - examples/beer/falcon.rb
287
- - examples/benchmark/config.ru
288
- - examples/benchmark/falcon.rb
289
- - examples/csv/config.ru
290
- - examples/google/falcon.rb
291
- - examples/hello/config.ru
292
- - examples/hello/falcon.rb
293
- - examples/hello/preload.rb
294
- - examples/internet/config.ru
295
- - examples/memory/allocations.rb
296
- - examples/memory/config.ru
297
- - examples/push/client.rb
298
- - examples/push/config.ru
299
- - examples/push/index.html
300
- - examples/push/script.js
301
- - examples/push/style.css
302
- - examples/redis/Gemfile
303
- - examples/redis/config.ru
304
- - examples/sequel/Gemfile
305
- - examples/sequel/config.ru
306
- - examples/sequel/data.sqlite3
307
- - examples/server/standalone.rb
308
- - examples/sinatra/Gemfile
309
- - examples/sinatra/Gemfile.lock
310
- - examples/sinatra/config.ru
311
- - examples/trailers/config.ru
312
- - examples/trailers/falcon.rb
313
- - falcon.gemspec
314
- - gems/rack1.gemfile
315
- - gems/rack3.gemfile
316
263
  - lib/falcon.rb
317
264
  - lib/falcon/adapters/early_hints.rb
318
265
  - lib/falcon/adapters/input.rb
@@ -330,22 +277,24 @@ files:
330
277
  - lib/falcon/command/top.rb
331
278
  - lib/falcon/command/virtual.rb
332
279
  - lib/falcon/configuration.rb
333
- - lib/falcon/configuration/application.rb
334
- - lib/falcon/configuration/lets_encrypt_tls.rb
335
- - lib/falcon/configuration/proxy.rb
336
- - lib/falcon/configuration/rack.rb
337
- - lib/falcon/configuration/self_signed_tls.rb
338
- - lib/falcon/configuration/supervisor.rb
339
- - lib/falcon/configuration/tls.rb
340
280
  - lib/falcon/controller/host.rb
341
281
  - lib/falcon/controller/proxy.rb
342
282
  - lib/falcon/controller/redirect.rb
343
283
  - lib/falcon/controller/serve.rb
344
284
  - lib/falcon/controller/virtual.rb
345
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
346
294
  - lib/falcon/extensions/openssl.rb
347
295
  - lib/falcon/middleware/proxy.rb
348
296
  - lib/falcon/middleware/redirect.rb
297
+ - lib/falcon/middleware/verbose.rb
349
298
  - lib/falcon/proxy_endpoint.rb
350
299
  - lib/falcon/server.rb
351
300
  - lib/falcon/service/application.rb
@@ -354,18 +303,12 @@ files:
354
303
  - lib/falcon/service/supervisor.rb
355
304
  - lib/falcon/services.rb
356
305
  - lib/falcon/tls.rb
357
- - lib/falcon/verbose.rb
358
306
  - lib/falcon/version.rb
359
307
  - lib/rack/handler/falcon.rb
360
- - logo-square.afdesign
361
- - logo.afdesign
362
- - logo.svg
363
- - server.rb
364
- - tasks/benchmark.rake
365
308
  homepage: https://github.com/socketry/falcon
366
309
  licenses: []
367
310
  metadata: {}
368
- post_install_message:
311
+ post_install_message:
369
312
  rdoc_options: []
370
313
  require_paths:
371
314
  - lib
@@ -373,7 +316,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
373
316
  requirements:
374
317
  - - "~>"
375
318
  - !ruby/object:Gem::Version
376
- version: '2.4'
319
+ version: '2.5'
377
320
  required_rubygems_version: !ruby/object:Gem::Requirement
378
321
  requirements:
379
322
  - - ">="
@@ -381,7 +324,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
381
324
  version: '0'
382
325
  requirements: []
383
326
  rubygems_version: 3.1.2
384
- signing_key:
327
+ signing_key:
385
328
  specification_version: 4
386
329
  summary: A fast, asynchronous, rack-compatible web server.
387
330
  test_files: []