falcon 0.48.4 → 0.48.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: 1b4caa19c4227d2fdeeb8a700a20be255a12f3bee3d2aa69ea31d9a8c7a2508b
4
- data.tar.gz: 6ae1117406cc230dad0447a43fd35ef94b1361dbe196a3e1e2ebd29700a7e228
3
+ metadata.gz: 8ef2381f9e160ea759eb3514031d4503c04f757b0678b5d7ad3342392a55bc5b
4
+ data.tar.gz: 688e89fbbf7b410fa3be7bb9d570e2d6047b750bae36237a17b6837766eefbd7
5
5
  SHA512:
6
- metadata.gz: 75086f0c0c1c552b9201d26b2ef3c3cc394ecb64c596642ff62ad73c361fac5493b867aa19becfd1aa4b6e0b7dfe1abba334c276df2ba5ca0dc194df759f007c
7
- data.tar.gz: d19a36195d9521d3ac0d7ae4db56b6521cfd0e2bfbaf5ade95408c8cd557d6bf3c8733cda818a84980c61fed3a05fce936af85fb53807d15216ab4d8a88733e1
6
+ metadata.gz: 7d183d3ea35bebecc7df5c360c20cda41fcf1e6b126f287d4dd9387d8911d0a24ef7b20221945efa9acd7451d9e9b053bef326bd9a53a0e55756fc283d427402
7
+ data.tar.gz: d9261f7e20b4d95d6519e1c70a70c34f0f243207ea72bbe8b9d340414b00ba73542229cc5c5d2a0054cef624fa0f1ff413bbb3580a27d610cbf46587459c43b0
checksums.yaml.gz.sig CHANGED
Binary file
@@ -152,6 +152,9 @@ module Falcon
152
152
  def call(request)
153
153
  attributes = {
154
154
  "authority" => request.authority,
155
+ "method" => request.method,
156
+ "path" => request.path,
157
+ "version" => request.version,
155
158
  }
156
159
 
157
160
  Traces.trace("falcon.middleware.proxy.call", attributes: attributes) do
@@ -50,6 +50,8 @@ module Falcon
50
50
  location = "#{@endpoint.scheme}://#{host.authority}:#{@endpoint.port}#{request.path}"
51
51
  end
52
52
 
53
+ Console.info(self, "Redirecting incoming request...", request: request, location: location)
54
+
53
55
  return Protocol::HTTP::Response[301, [["location", location]], []]
54
56
  else
55
57
  super
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2025, by Samuel Williams.
5
+
6
+ module Falcon
7
+ module Middleware
8
+ # A HTTP middleware for validating incoming requests.
9
+ class Validate < Protocol::HTTP::Middleware
10
+ # Initialize the validate middleware.
11
+ # @parameter app [Protocol::HTTP::Middleware] The middleware to wrap.
12
+ def initialize(app)
13
+ super(app)
14
+ end
15
+
16
+ # Validate the incoming request.
17
+ def call(request)
18
+ unless request.path.start_with?("/")
19
+ return Protocol::HTTP::Response[400, {}, ["Invalid request path!"]]
20
+ end
21
+
22
+ return super
23
+ end
24
+ end
25
+ end
26
+ end
@@ -13,7 +13,7 @@ module Falcon
13
13
  # Initialize the verbose middleware.
14
14
  # @parameter app [Protocol::HTTP::Middleware] The middleware to wrap.
15
15
  # @parameter logger [Console::Logger] The logger to use.
16
- def initialize(app, logger = Console.logger)
16
+ def initialize(app, logger = Console)
17
17
  super(app)
18
18
 
19
19
  @logger = logger
@@ -24,7 +24,7 @@ module Falcon
24
24
  task = Async::Task.current
25
25
  address = request.remote_address
26
26
 
27
- @logger.info(request) {"Headers: #{request.headers.to_h} from #{address.inspect}"}
27
+ @logger.info(request, "-> #{request.method} #{request.path}", headers: request.headers.to_h, address: address.inspect)
28
28
 
29
29
  task.annotate("#{request.method} #{request.path} from #{address.inspect}")
30
30
  end
@@ -37,10 +37,8 @@ module Falcon
37
37
 
38
38
  response = super
39
39
 
40
- statistics.wrap(response) do |statistics, error|
41
- @logger.info(request) {"Responding with: #{response.status} #{response.headers.to_h}; #{statistics.inspect}"}
42
-
43
- @logger.error(request) {"#{error.class}: #{error.message}"} if error
40
+ statistics.wrap(response) do |body, error|
41
+ @logger.info(request, "<- #{request.method} #{request.path}", headers: response.headers.to_h, status: response.status, body: body.inspect, error: error)
44
42
  end
45
43
 
46
44
  return response
data/lib/falcon/server.rb CHANGED
@@ -9,8 +9,8 @@ require "protocol/http/middleware/builder"
9
9
  require "protocol/http/content_encoding"
10
10
 
11
11
  require "async/http/cache"
12
-
13
12
  require_relative "middleware/verbose"
13
+ require_relative "middleware/validate"
14
14
  require "protocol/rack"
15
15
 
16
16
  module Falcon
@@ -18,21 +18,26 @@ module Falcon
18
18
  class Server < Async::HTTP::Server
19
19
  # Wrap a rack application into a middleware suitable the server.
20
20
  # @parameter rack_app [Proc | Object] A rack application/middleware.
21
- # @parameter verbose [Boolean] Whether to add the {Verbose} middleware.
21
+ # @parameter validate [Boolean] Whether to add the {Middleware::Validate} middleware.
22
+ # @parameter verbose [Boolean] Whether to add the {Middleware::Verbose} middleware.
22
23
  # @parameter cache [Boolean] Whether to add the {Async::HTTP::Cache} middleware.
23
- def self.middleware(rack_app, verbose: false, cache: true)
24
+ def self.middleware(rack_app, verbose: false, validate: true, cache: true)
24
25
  ::Protocol::HTTP::Middleware.build do
25
26
  if verbose
26
27
  use Middleware::Verbose
27
28
  end
28
29
 
30
+ if validate
31
+ use Middleware::Validate
32
+ end
33
+
29
34
  if cache
30
35
  use Async::HTTP::Cache::General
31
36
  end
32
37
 
33
38
  use ::Protocol::HTTP::ContentEncoding
34
- use ::Protocol::Rack::Adapter
35
39
 
40
+ use ::Protocol::Rack::Adapter
36
41
  run rack_app
37
42
  end
38
43
  end
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2017-2024, by Samuel Williams.
5
5
 
6
6
  module Falcon
7
- VERSION = "0.48.4"
7
+ VERSION = "0.48.5"
8
8
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: falcon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.48.4
4
+ version: 0.48.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -29,7 +29,6 @@ authors:
29
29
  - Stefan Buhrmester
30
30
  - Tad Thorley
31
31
  - Tasos Latsas
32
- autorequire:
33
32
  bindir: bin
34
33
  cert_chain:
35
34
  - |
@@ -61,7 +60,7 @@ cert_chain:
61
60
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
62
61
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
63
62
  -----END CERTIFICATE-----
64
- date: 2025-01-04 00:00:00.000000000 Z
63
+ date: 2025-01-28 00:00:00.000000000 Z
65
64
  dependencies:
66
65
  - !ruby/object:Gem::Dependency
67
66
  name: async
@@ -231,8 +230,6 @@ dependencies:
231
230
  - - "~>"
232
231
  - !ruby/object:Gem::Version
233
232
  version: '2.3'
234
- description:
235
- email:
236
233
  executables:
237
234
  - falcon
238
235
  - falcon-host
@@ -270,6 +267,7 @@ files:
270
267
  - lib/falcon/environment/virtual.rb
271
268
  - lib/falcon/middleware/proxy.rb
272
269
  - lib/falcon/middleware/redirect.rb
270
+ - lib/falcon/middleware/validate.rb
273
271
  - lib/falcon/middleware/verbose.rb
274
272
  - lib/falcon/proxy_endpoint.rb
275
273
  - lib/falcon/rackup/handler.rb
@@ -291,7 +289,6 @@ licenses:
291
289
  metadata:
292
290
  documentation_uri: https://socketry.github.io/falcon/
293
291
  source_code_uri: https://github.com/socketry/falcon.git
294
- post_install_message:
295
292
  rdoc_options: []
296
293
  require_paths:
297
294
  - lib
@@ -306,8 +303,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
306
303
  - !ruby/object:Gem::Version
307
304
  version: '0'
308
305
  requirements: []
309
- rubygems_version: 3.5.22
310
- signing_key:
306
+ rubygems_version: 3.6.2
311
307
  specification_version: 4
312
308
  summary: A fast, asynchronous, rack-compatible web server.
313
309
  test_files: []
metadata.gz.sig CHANGED
Binary file