In the past I've used this solution, but since Rails 5 deprecated ParamsParser
middleware, it doesn't work anymore.
Just add:
# 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
You can test it with:
# config/routes.rb
post '/', to: 'welcome#create'
# app/controllers/welcome_controller.rb
class WelcomeController < ActionController::Base
def create
render json: params
end
end
And do the request:
curl --data-binary @<(echo "Uncompressed data" | gzip) \
-H "CONTENT_ENCODING: gzip" \
localhost:3000
{"Uncompressed data\n":null,"controller":"welcome","action":"create"}%
If you have NginX in front of Unicorns, then you can just tell NginX to uncompress the data for you
http://www.pataliebre.net/howto-make-nginx-decompress-a-gzipped-request.html#.WBzSt-ErIUE
https://www.nginx.com/resources/admin-guide/compression-and-decompression/
this should work if you insert the middleware right before Rack::Head
config.middleware.insert_before Rack::Head, "CompressedRequests"
this should do the trick
you can check your app's middleware stack with the following command
rake middleware
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With