当编码为gzip时,我读到了Net :: HTTP自动解压缩文件... 我正在下载xml文件,但是保存在我的文件夹中的文件仍然是.gz文件。 有事吗?
uri = URI(URI.encode(URL))
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
request = Net::HTTP::Get.new(uri.path, { "Accept-Encoding" => "gzip", "User-Agent" => "gzip" })
request.basic_auth AUTHENTICATION[:username], AUTHENTICATION[:password]
http.request request do |response|
open "./storage/file/index_full.xml.gz", 'wb' do |io|
response.read_body do |chunk|
puts "Writing #{chunk.length} bits ..."
io.write chunk
end
end
end
end
答案 0 :(得分:0)
documentation声称Net :: HTTP自动解压缩压缩的响应。为此,客户端必须设置Accept-Encoding
标头,服务器必须将Content-Encoding
标头设置为described here。
您正在使用的服务器未设置Content-Encoding
头,因此客户端不会解压缩响应。
服务器确实发送了gzip压缩的字节流,但这还不够。 (如果所有客户端都解压缩了gzip压缩的所有内容,则您将无法按原样下载任何.tar.gz
文件。)