Skip to content

Instantly share code, notes, and snippets.

@indirect
Created March 6, 2014 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indirect/9400480 to your computer and use it in GitHub Desktop.
Save indirect/9400480 to your computer and use it in GitHub Desktop.
Repro case for Ruby 2.0 Content-Disposition: gzip handling
require 'sinatra'
require 'zlib'
configure do
set :server, :puma
end
get '/text' do
body File.read("text")
end
get '/text.gz' do
body File.read("text.gz")
end
get '/z/text' do
gzip_body File.read("text")
end
get '/z/text.gz' do
gzip_body File.read("text.gz")
end
def gzip_body(body)
headers['Content-Encoding'] = 'gzip'
io = StringIO.new
gz = Zlib::GzipWriter.new(io)
begin
gz.write(body)
ensure
gz.close
end
body(io.string)
end
# run ruby app.rb first so that this can run against it
require 'net/http'
def get(url)
Net::HTTP.new("localhost", 4567).request(Net::HTTP::Get.new(url)).body
end
urls = %w(/text /text.gz /z/text /z/text.gz)
urls.each do |url|
puts "requesting #{url}: #{get(url)}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment