rage-rb 1.8.0 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/lib/rage/cli.rb +12 -5
- data/lib/rage/configuration.rb +14 -0
- data/lib/rage/ext/active_record/connection_pool.rb +11 -3
- data/lib/rage/ext/setup.rb +1 -1
- data/lib/rage/rails.rb +4 -1
- data/lib/rage/request.rb +39 -0
- data/lib/rage/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8b2423a2cb780fd3f8ffc4e76a6690fff37162836e3d2d64791c7f058b3d63f
|
4
|
+
data.tar.gz: 86c2ee3464e5668e78409d7eae2e987c4e6a5aa54bea024c7cca694dd142019e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc810e46ff275e4595c2631f3cb5cbd19d38dd42885b393bb240ffb8b96ff6cb6f0f93015a461c469cbb88e13cbcc53288f385db590bd2562dc604a4d38b423e
|
7
|
+
data.tar.gz: 6be5256d0c92fd495f6afa2ba3d9f6a08cfe6058429040f10d035594ad9a54d050241fa443029836042e7435681563f36bfee89b04eecaeb31055206adff41ef
|
data/CHANGELOG.md
CHANGED
data/lib/rage/cli.rb
CHANGED
@@ -29,12 +29,15 @@ module Rage
|
|
29
29
|
app = ::Rack::Builder.parse_file(options[:config] || "config.ru")
|
30
30
|
app = app[0] if app.is_a?(Array)
|
31
31
|
|
32
|
-
|
33
|
-
address = options[:binding] || (Rage.env.production? ? "0.0.0.0" : "localhost")
|
34
|
-
timeout = Rage.config.server.timeout
|
35
|
-
max_clients = Rage.config.server.max_clients
|
32
|
+
server_options = { service: :http, handler: app }
|
36
33
|
|
37
|
-
|
34
|
+
server_options[:port] = options[:port] || Rage.config.server.port
|
35
|
+
server_options[:address] = options[:binding] || (Rage.env.production? ? "0.0.0.0" : "localhost")
|
36
|
+
server_options[:timeout] = Rage.config.server.timeout
|
37
|
+
server_options[:max_clients] = Rage.config.server.max_clients
|
38
|
+
server_options[:public] = Rage.config.public_file_server.enabled ? Rage.root.join("public").to_s : nil
|
39
|
+
|
40
|
+
::Iodine.listen(**server_options)
|
38
41
|
::Iodine.threads = Rage.config.server.threads_count
|
39
42
|
::Iodine.workers = Rage.config.server.workers_count
|
40
43
|
|
@@ -124,6 +127,10 @@ module Rage
|
|
124
127
|
|
125
128
|
def set_env(options)
|
126
129
|
ENV["RAGE_ENV"] = options[:environment] if options[:environment]
|
130
|
+
|
131
|
+
# at this point we don't know whether the app is running in standalone or Rails mode;
|
132
|
+
# we set both variables to make sure applications are running in the same environment;
|
133
|
+
ENV["RAILS_ENV"] = ENV["RAGE_ENV"] if ENV["RAGE_ENV"] && ENV["RAILS_ENV"] != ENV["RAGE_ENV"]
|
127
134
|
end
|
128
135
|
end
|
129
136
|
|
data/lib/rage/configuration.rb
CHANGED
@@ -102,6 +102,12 @@
|
|
102
102
|
#
|
103
103
|
# > Specifies connection timeout.
|
104
104
|
#
|
105
|
+
# # Static file server
|
106
|
+
#
|
107
|
+
# • _config.public_file_server.enabled_
|
108
|
+
#
|
109
|
+
# > Configures whether Rage should serve static files from the public directory. Defaults to `false`.
|
110
|
+
#
|
105
111
|
# # Cable Configuration
|
106
112
|
#
|
107
113
|
# • _config.cable.protocol_
|
@@ -165,6 +171,10 @@ class Rage::Configuration
|
|
165
171
|
@cable ||= Cable.new
|
166
172
|
end
|
167
173
|
|
174
|
+
def public_file_server
|
175
|
+
@public_file_server ||= PublicFileServer.new
|
176
|
+
end
|
177
|
+
|
168
178
|
def internal
|
169
179
|
@internal ||= Internal.new
|
170
180
|
end
|
@@ -246,6 +256,10 @@ class Rage::Configuration
|
|
246
256
|
end
|
247
257
|
end
|
248
258
|
|
259
|
+
class PublicFileServer
|
260
|
+
attr_accessor :enabled
|
261
|
+
end
|
262
|
+
|
249
263
|
# @private
|
250
264
|
class Internal
|
251
265
|
attr_accessor :rails_mode
|
@@ -148,10 +148,14 @@ module Rage::Ext::ActiveRecord::ConnectionPool
|
|
148
148
|
end
|
149
149
|
|
150
150
|
# Yields a connection from the connection pool to the block.
|
151
|
-
def with_connection
|
152
|
-
|
151
|
+
def with_connection(_ = nil)
|
152
|
+
unless (conn = @__in_use[Fiber.current])
|
153
|
+
conn = connection
|
154
|
+
fresh_connection = true
|
155
|
+
end
|
156
|
+
yield conn
|
153
157
|
ensure
|
154
|
-
release_connection
|
158
|
+
release_connection if fresh_connection
|
155
159
|
end
|
156
160
|
|
157
161
|
# Returns an array containing the connections currently in the pool.
|
@@ -230,6 +234,10 @@ module Rage::Ext::ActiveRecord::ConnectionPool
|
|
230
234
|
connection
|
231
235
|
end
|
232
236
|
|
237
|
+
def lease_connection
|
238
|
+
connection
|
239
|
+
end
|
240
|
+
|
233
241
|
# Check in a database connection back into the pool, indicating that you no longer need this connection.
|
234
242
|
def checkin(conn)
|
235
243
|
fiber = @__in_use.key(conn)
|
data/lib/rage/ext/setup.rb
CHANGED
@@ -31,6 +31,6 @@ if defined?(ActiveRecord::ConnectionAdapters::ConnectionPool)
|
|
31
31
|
end
|
32
32
|
|
33
33
|
# patch `ActiveRecord::ConnectionPool`
|
34
|
-
if defined?(ActiveRecord) && ENV["RAGE_PATCH_AR_POOL"]
|
34
|
+
if defined?(ActiveRecord) && ENV["RAGE_PATCH_AR_POOL"] && !Rage.env.test?
|
35
35
|
Rage.patch_active_record_connection_pool
|
36
36
|
end
|
data/lib/rage/rails.rb
CHANGED
@@ -44,7 +44,10 @@ end
|
|
44
44
|
# clone Rails logger
|
45
45
|
Rails.configuration.after_initialize do
|
46
46
|
if Rails.logger && !Rage.logger
|
47
|
-
rails_logdev = Rails.logger.
|
47
|
+
rails_logdev = Rails.logger.yield_self { |logger|
|
48
|
+
logger.respond_to?(:broadcasts) ? logger.broadcasts.last : logger
|
49
|
+
}.instance_variable_get(:@logdev)
|
50
|
+
|
48
51
|
Rage.configure do
|
49
52
|
config.logger = Rage::Logger.new(rails_logdev.dev) if rails_logdev.is_a?(Logger::LogDevice)
|
50
53
|
end
|
data/lib/rage/request.rb
CHANGED
@@ -37,6 +37,45 @@ class Rage::Request
|
|
37
37
|
)
|
38
38
|
end
|
39
39
|
|
40
|
+
# Returns the full URL of the request.
|
41
|
+
# @example
|
42
|
+
# request.url # => "https://example.com/users?show_archived=true"
|
43
|
+
def url
|
44
|
+
scheme = @env["rack.url_scheme"]
|
45
|
+
host = @env["SERVER_NAME"]
|
46
|
+
port = @env["SERVER_PORT"]
|
47
|
+
path = @env["PATH_INFO"]
|
48
|
+
query_string = @env["QUERY_STRING"]
|
49
|
+
|
50
|
+
port_part = (scheme == "http" && port == "80") || (scheme == "https" && port == "443") ? "" : ":#{port}"
|
51
|
+
query_part = query_string.empty? ? "" : "?#{query_string}"
|
52
|
+
|
53
|
+
"#{scheme}://#{host}#{port_part}#{path}#{query_part}"
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns the path of the request.
|
57
|
+
# @example
|
58
|
+
# request.path # => "/users"
|
59
|
+
def path
|
60
|
+
@env["PATH_INFO"]
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns the full path including the query string.
|
64
|
+
# @example
|
65
|
+
# request.fullpath # => "/users?show_archived=true"
|
66
|
+
def fullpath
|
67
|
+
path = @env["PATH_INFO"]
|
68
|
+
query_string = @env["QUERY_STRING"]
|
69
|
+
query_string.empty? ? path : "#{path}?#{query_string}"
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns the user agent of the request.
|
73
|
+
# @example
|
74
|
+
# request.user_agent # => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36"
|
75
|
+
def user_agent
|
76
|
+
@env["HTTP_USER_AGENT"]
|
77
|
+
end
|
78
|
+
|
40
79
|
private
|
41
80
|
|
42
81
|
def if_none_match
|
data/lib/rage/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rage-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Samoilov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|