过去我使用过this solution,但是自从Rails 5 deprecated ParamsParser
中间件后,它就再也无法使用了。
答案 0 :(得分:6)
只需添加:
# config/initializers/middlewares.rb
require 'compressed_requests'
Rails.application.configure do
config.middleware.insert_after Rack::Sendfile, CompressedRequests
end
# lib/compressed_requests.rb
# Copy the file from the article
您可以使用以下方法进行测试:
# config/routes.rb
post '/', to: 'welcome#create'
# app/controllers/welcome_controller.rb
class WelcomeController < ActionController::Base
def create
render json: params
end
end
请求:
curl --data-binary @<(echo "Uncompressed data" | gzip) \
-H "CONTENT_ENCODING: gzip" \
localhost:3000
{"Uncompressed data\n":null,"controller":"welcome","action":"create"}%
答案 1 :(得分:3)
如果您在Rack::Head
config.middleware.insert_before Rack::Head, "CompressedRequests"
这应该可以解决问题
您可以使用以下命令检查应用的中间件堆栈
rake middleware
答案 2 :(得分:3)
如果您在Unicorns前面有NginX,那么您可以告诉NginX为您解压缩数据
http://www.pataliebre.net/howto-make-nginx-decompress-a-gzipped-request.html#.WBzSt-ErIUE
https://www.nginx.com/resources/admin-guide/compression-and-decompression/
答案 3 :(得分:2)