Created
March 6, 2014 21:52
-
-
Save indirect/9400480 to your computer and use it in GitHub Desktop.
Repro case for Ruby 2.0 Content-Disposition: gzip handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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