falcon 0.35.4 → 0.35.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5096cf9dd5938f5ab21783443a39b0f913a7642ee77c40dcac2e6fe7fb5b442
4
- data.tar.gz: a16d8aac26ba68a1b18978eba9b7afb62195ae6d31a5811723f6eab6686ba1a3
3
+ metadata.gz: e83bfe3390b43efac4ff13076a198647d1b0e4da68c9341fb6253a70f03c65d3
4
+ data.tar.gz: 0c915210a960b159ced61e91f807c63ffae9f3b22313e1f1b806ffa83422a529
5
5
  SHA512:
6
- metadata.gz: 15362126885ff2e18af583d19549b7c7d694de1af5a861bf35b35db03911f70b4d324ac04ead25a49ccb95cccf528c02020b15687f38b75dcca3243d2c82c98d
7
- data.tar.gz: 9b94bb69571af1a9594fe55caf78847386143427353370eaa04f7ee9a51d53aade8b79d91d82537c295c397b1cae0d15e8fdd637c71c18d950aff2fc21800c8a
6
+ metadata.gz: f97f776a63c1541874af780652096e5dee4e197ccaf04a1c3e2b5c4d6b72a508b29527281f5d5e6e6c64ec40fdc3c6e16a66e69dd44cafb407326c77977a503c
7
+ data.tar.gz: c4aae4c9610fb77e017e5f91bab938855b24662d80a5188b199397e98c41d42c6fc84db5ad377ec13cfb01610a2819a23c9c431092d67d39cfb9f06be73d4c54
data/README.md CHANGED
@@ -273,7 +273,7 @@ Falcon can be an important part of your business or project, both improving perf
273
273
  - Priority consideration of feature requests and bug reports.
274
274
  - Private support and assistance via direct email.
275
275
 
276
- The standard price for business support is $120.00 USD / year / production instance (including reserve instances). Please [contact us](mailto:context@oriontransfer.net?subject=Falcon%20Business%20Support) for more details.
276
+ The standard price for business support is $120.00 USD / year / production instance (including reserve instances). Please [contact us](mailto:contact@oriontransfer.net?subject=Falcon%20Business%20Support) for more details.
277
277
 
278
278
  ### "Stretch" Goals
279
279
 
data/bin/falcon CHANGED
@@ -25,4 +25,8 @@ require_relative '../lib/falcon/command'
25
25
  begin
26
26
  Falcon::Command.call
27
27
  rescue Interrupt
28
+ # Ignore.
29
+ rescue => error
30
+ Async.logger.error(Falcon::Command) {error}
31
+ exit! 1
28
32
  end
@@ -17,6 +17,6 @@ class RequestLogger
17
17
  end
18
18
  end
19
19
 
20
- use RequestLogger
20
+ # use RequestLogger
21
21
 
22
- run lambda {|env| Async.logger.debug(self) {env['HTTP_USER_AGENT']}; [200, {}, ["Hello World"]]}
22
+ run lambda {|env| [200, {'cache-control' => 'max-age=10, public'}, ["Hello World"]]}
@@ -29,7 +29,7 @@ GEM
29
29
  rack
30
30
  rainbow (2.2.2)
31
31
  rake
32
- rake (12.3.1)
32
+ rake (13.0.1)
33
33
  samovar (1.8.0)
34
34
  mapping (~> 1.0)
35
35
  rainbow (~> 2.0)
@@ -21,7 +21,8 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_dependency "async", "~> 1.13"
23
23
  spec.add_dependency "async-io", "~> 1.22"
24
- spec.add_dependency "async-http", "~> 0.50.0"
24
+ spec.add_dependency "async-http", "~> 0.50.4"
25
+ spec.add_dependency "async-http-cache", "~> 0.1.0"
25
26
  spec.add_dependency "async-container", "~> 0.16.0"
26
27
 
27
28
  spec.add_dependency "rack", ">= 1.0"
@@ -41,7 +41,7 @@ require 'bundler'
41
41
  module Falcon
42
42
  module Command
43
43
  class Serve < Samovar::Command
44
- self.description = "Run an HTTP server."
44
+ self.description = "Run an HTTP server for development purposes."
45
45
 
46
46
  options do
47
47
  option '-b/--bind <address>', "Bind to the given hostname/address.", default: "https://localhost:9292"
@@ -51,7 +51,9 @@ module Falcon
51
51
  option '-t/--timeout <duration>', "Specify the maximum time to wait for non-blocking operations.", type: Float, default: nil
52
52
 
53
53
  option '-c/--config <path>', "Rackup configuration file to load.", default: 'config.ru'
54
- option '--preload', "Preload the bundle before creating containers."
54
+ option '--preload <path>', "Preload the specified path before creating containers."
55
+
56
+ option '--cache', "Enable the response cache."
55
57
 
56
58
  option '--forked | --threaded | --hybrid', "Select a specific parallelism model.", key: :container, default: :forked
57
59
 
@@ -76,10 +78,14 @@ module Falcon
76
78
  @parent&.verbose?
77
79
  end
78
80
 
79
- def load_app(verbose = self.verbose?)
80
- rack_app, options = Rack::Builder.parse_file(@options[:config])
81
+ def cache?
82
+ @options[:cache]
83
+ end
84
+
85
+ def load_app
86
+ rack_app, _ = Rack::Builder.parse_file(@options[:config])
81
87
 
82
- return Server.middleware(rack_app, verbose: verbose), options
88
+ return Server.middleware(rack_app, verbose: self.verbose?, cache: self.cache?)
83
89
  end
84
90
 
85
91
  def slice_options(*keys)
@@ -120,14 +126,20 @@ module Falcon
120
126
  end
121
127
 
122
128
  def call
123
- Async.logger.info(self.endpoint) do |buffer|
129
+ Async.logger.info(self) do |buffer|
124
130
  buffer.puts "Falcon v#{VERSION} taking flight! Using #{self.container_class} #{self.container_options}."
131
+ buffer.puts "- Binding to: #{self.endpoint}"
125
132
  buffer.puts "- To terminate: Ctrl-C or kill #{Process.pid}"
126
133
  buffer.puts "- To reload configuration: kill -HUP #{Process.pid}"
127
134
  end
128
135
 
129
- if @options[:preload]
130
- Bundler.require(:preload)
136
+ if path = @options[:preload]
137
+ full_path = File.expand_path(path)
138
+ load(full_path)
139
+ end
140
+
141
+ if GC.respond_to?(:compact)
142
+ GC.compact
131
143
  end
132
144
 
133
145
  self.controller.run
@@ -40,6 +40,7 @@ module Falcon
40
40
  option '--verbose | --quiet', "Verbosity of output for debugging.", key: :logging
41
41
  option '-h/--help', "Print out help information."
42
42
  option '-v/--version', "Print out the application version."
43
+ option '-e/--encoding', "Specify the default external encoding of the server.", default: "UTF-8"
43
44
  end
44
45
 
45
46
  nested :command, {
@@ -59,15 +60,27 @@ module Falcon
59
60
  @options[:logging] == :quiet
60
61
  end
61
62
 
63
+ # If you don't specify these, it's possible to have issues when encodings mismatch on the server.
64
+ def update_external_encoding!(encoding = Encoding::UTF_8)
65
+ if Encoding.default_external != encoding
66
+ Console.logger.warn(self) {"Updating Encoding.default_external from #{Encoding.default_external} to #{encoding}"}
67
+ Encoding.default_external = encoding
68
+ end
69
+ end
70
+
71
+ def encoding
72
+ if name = @options[:encoding]
73
+ Encoding.find(name)
74
+ end
75
+ end
76
+
62
77
  def call
63
- # if verbose?
64
- # Async.logger.debug!
65
- # elsif quiet?
66
- # Async.logger.warn!
67
- # else
68
- # Async.logger.info!
69
- # end
70
- #
78
+ if encoding = self.encoding
79
+ update_external_encoding!(encoding)
80
+ else
81
+ update_external_encoding!
82
+ end
83
+
71
84
  if @options[:version]
72
85
  puts "#{self.name} v#{Falcon::VERSION}"
73
86
  elsif @options[:help]
@@ -25,9 +25,14 @@ load :application
25
25
  add(:rack, :application) do
26
26
  config_path {::File.expand_path("config.ru", root)}
27
27
 
28
+ cache true
29
+
28
30
  middleware do
29
- ::Falcon::Server.middleware(
30
- ::Rack::Builder.parse_file(config_path).first, verbose: verbose
31
+ app, _ = ::Rack::Builder.parse_file(config_path)
32
+
33
+ ::Falcon::Server.middleware(app,
34
+ verbose: verbose,
35
+ cache: cache
31
36
  )
32
37
  end
33
38
  end
@@ -69,14 +69,10 @@ module Falcon
69
69
  end
70
70
 
71
71
  def setup(container)
72
- app, _ = self.load_app
73
-
74
- if GC.respond_to?(:compact)
75
- GC.compact
76
- end
77
-
78
72
  container.run(name: self.name, restart: true, **@command.container_options) do |instance|
79
73
  Async do |task|
74
+ app = self.load_app
75
+
80
76
  task.async do
81
77
  if @debug_trap.install!
82
78
  Async.logger.info(instance) do
@@ -25,18 +25,24 @@ require 'async/http/server'
25
25
  require 'protocol/http/middleware/builder'
26
26
  require 'protocol/http/content_encoding'
27
27
 
28
+ require 'async/http/cache'
29
+
28
30
  require_relative 'verbose'
29
31
  require_relative 'adapters/rewindable'
30
32
  require_relative 'adapters/rack'
31
33
 
32
34
  module Falcon
33
35
  class Server < Async::HTTP::Server
34
- def self.middleware(rack_app, verbose: false)
36
+ def self.middleware(rack_app, verbose: false, cache: true)
35
37
  ::Protocol::HTTP::Middleware.build do
36
38
  if verbose
37
39
  use Verbose
38
40
  end
39
41
 
42
+ if cache
43
+ use Async::HTTP::Cache::General
44
+ end
45
+
40
46
  use ::Protocol::HTTP::ContentEncoding
41
47
  use Adapters::Rewindable
42
48
  use Adapters::Rack
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Falcon
24
- VERSION = "0.35.4"
24
+ VERSION = "0.35.5"
25
25
  end
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.35.4
4
+ version: 0.35.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-20 00:00:00.000000000 Z
11
+ date: 2020-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -44,14 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.50.0
47
+ version: 0.50.4
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.50.0
54
+ version: 0.50.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: async-http-cache
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: async-container
57
71
  requirement: !ruby/object:Gem::Requirement