Bug #9562

Cannot install gems from gzip-compressing gem server

Added by 5 5 about 1 year ago. Updated 8 months ago.

[ruby-dev:48015]
Status:Rejected
Priority:Normal
Assignee:Eric Hodel
ruby -v:ruby 2.0.0p353 (2013-11-22) [i386-mingw32] Backport:1.9.3: DONTNEED, 2.0.0: REQUIRED, 2.1: REQUIRED

Description

gem generate_index で作成した gem server が gzip 圧縮を行う場合,Ruby 2.0 以上では gem のインストールに失敗します。

Ruby 1.9 では正常です。

サーバーを gzip 圧縮しない設定にすれば問題が解消します。

History

#1 Updated by Yui NARUSE about 1 year ago

  • Target version set to current: 2.2.0
  • Status changed from Open to Assigned
  • Assignee set to Eric Hodel
  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN to 1.9.3: DONTNEED, 2.0.0: REQUIRED, 2.1: REQUIRED

You know, since Ruby 2.0.0, net/http automatically decode content-encoding;gzip.
Therefore Gem::Request, which uses Net::HTTP internally, also decode gz file, for example specs.4.8.gz,
if a gemsource server sets Content-Encoding: gzip to gz files.

Individual gem servers may hit this issue if people accidentally set Content-Encoding: gzip.
I think this issue should be avoided by RubyGems, and a patch may be following:

diff --git a/lib/rubygems/request.rb b/lib/rubygems/request.rb
index d2f076f..588dae4 100644
--- a/lib/rubygems/request.rb
+++ b/lib/rubygems/request.rb
@@ -112,6 +112,7 @@ class Gem::Request
request.add_field 'User-Agent', @user_agent
request.add_field 'Connection', 'keep-alive'
request.add_field 'Keep-Alive', '30'
+    request.add_field 'Accept-Encoding', ''
if @last_modified then
request.add_field 'If-Modified-Since', @last_modified.httpdate

#2 Updated by Eric Hodel about 1 year ago

  • Status changed from Assigned to Rejected

If the server does not return a gzip Content-Type for a .gz file it is misconfigured. This is not a bug in rubygems.

#3 Updated by Akinori MUSHA about 1 year ago

Eric, I think the problem is that Gem::RemoteFetcher#fetch_path fails in Gem.gunzip data if the data is already decoded by Net::HTTP of Ruby 2.0 and later.
It happens when the HTTP server is configured to set a Content-Encoding: gzip header for .gz files, which itself is not necessarily a misconfiguration.

#4 Updated by Tomoyuki Chikanaga 8 months ago

ping?

Also available in: Atom PDF