Skip to content

Commit 8eeeaaf

Browse files
committed
[rails] Mark as production
Rails uses standard framework configuration. Use Rack::Deflater middleware for gzip.
1 parent 0566d2d commit 8eeeaaf

3 files changed

Lines changed: 6 additions & 21 deletions

File tree

frameworks/rails/app/controllers/benchmark_controller.rb

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,7 @@ def json_endpoint
4040
d.merge(total: d[:price] * d[:quantity] * m)
4141
end
4242

43-
result = JSON.generate(items: items, count: items.length)
44-
45-
if accept_encodings = request.headers['Accept-Encoding']
46-
types = accept_encodings.split(',').map(&:strip)
47-
if types.include? 'gzip'
48-
sio = StringIO.new
49-
gz = Zlib::GzipWriter.new(sio, 1)
50-
gz.write(result)
51-
gz.close
52-
response.headers['content-type'] = 'application/json'
53-
response.headers['content-encoding'] = 'gzip'
54-
send_data sio.string, disposition: :inline
55-
else
56-
render json: result
57-
end
58-
else
59-
render json: result
60-
end
43+
render json: JSON.generate(items: items, count: items.length)
6144
end
6245

6346
def async_db

frameworks/rails/config/application.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ class BenchmarkApp < Rails::Application
2020
# Disable all middleware we don't need
2121
config.middleware.delete ActionDispatch::HostAuthorization
2222
config.middleware.delete ActionDispatch::Callbacks
23-
config.middleware.delete ActionDispatch::ActionableExceptions
2423
config.middleware.delete ActionDispatch::RemoteIp
2524
config.middleware.delete ActionDispatch::RequestId
2625
config.middleware.delete Rails::Rack::Logger
2726
config.middleware.delete ActionDispatch::ShowExceptions
2827

28+
# Add gzip support
29+
config.middleware.insert Rack::Deflater
30+
2931
# Catch unknown HTTP methods, routing errors, and mark /upload as binary
3032
config.middleware.insert_before 0, Class.new {
3133
VALID_METHODS = %w[GET HEAD POST PUT DELETE PATCH OPTIONS TRACE].to_set.freeze

frameworks/rails/meta.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"display_name": "rails",
33
"language": "Ruby",
4-
"type": "tuned",
4+
"type": "production",
55
"engine": "puma",
66
"description": "Ruby on Rails (API mode) on Puma, multi-worker with one worker per CPU core.",
77
"repo": "https://github.com/rails/rails",
@@ -19,4 +19,4 @@
1919
"static"
2020
],
2121
"maintainers": []
22-
}
22+
}

0 commit comments

Comments
 (0)