Accept-Encoding: gzip
# application.rb config.middleware.use Rack::Deflater
# config/initializers/mime_types.rb Mime::Type.register "gizp/json", :gzipjson ActionDispatch::ParamsParser::DEFAULT_PARSERS[Mime::Type.lookup('gzip/json')]=lambda do |raw_body| body = ActiveSupport::Gzip.decompress(raw_body) JSON.parse(body).with_indifferent_access end
# rack_deflater_spec.rb require 'spec_helper' describe Rack::Deflater do include_context 'API' it "encodes response if requested" do api_get "posts" response.headers["Content-Encoding"].should be_nil content_length = response.headers["Content-Length"].to_i api_get_gzipped "posts" response.headers["Content-Length"].to_i.should <= content_length response.headers["Content-Encoding"].should == "gzip" end it "accepts gzip encoded data" do api_post_gziped "posts", post: { name: 'Compressed' } response.headers["Content-Encoding"].should == "gzip" response.status.should eq 201 decompressed_json_body.should include 'name' => 'Compressed' end end
/