2 class CompressedRequests
7 def method_handled?(env)
8 %w[POST PUT].include? env["REQUEST_METHOD"]
11 def encoding_handled?(env)
12 %w[gzip deflate].include? env["HTTP_CONTENT_ENCODING"]
16 if method_handled?(env) && encoding_handled?(env)
17 extracted = decode(env["rack.input"], env["HTTP_CONTENT_ENCODING"])
19 env.delete("HTTP_CONTENT_ENCODING")
20 env["CONTENT_LENGTH"] = extracted.bytesize
21 env["rack.input"] = StringIO.new(extracted)
24 if env["HTTP_CONTENT_ENCODING"]
31 def decode(input, content_encoding)
35 when "gzip" then Zlib::GzipReader.new(input).read
36 when "deflate" then Zlib::Inflate.inflate(input.read)
42 Rails.configuration.middleware.use OpenStreetMap::CompressedRequests