Bug #501

rubygems fails to cache spec file

Added by mame (Yusuke Endoh) over 3 years ago. Updated about 1 year ago.

[ruby-core:18387]
Status:Closed Start date:
Priority:Low Due date:11/25/2008
Assignee:drbrain (Eric Hodel) % Done:

0%

Category:lib
Target version:1.9.1 Release Candidate
ruby -v:

Description

Hi,

I realized "gem update" always fetched the whole spec file
from gems.rubyforge.org even if rubygems has cache.

rubygems certainly sends If-Modified-Since field to the
server.  But the rubyforge server ignores it.
I confirmed this by using WEBrick::HTTPProxyServer.


This is because Apache, which rubyforge uses, seems to handle
If-Modified-Since field only when it is represented in GMT.
This is not a fault of rubygems, but I think it's better for
rubygems to convert last_modified in GMT.


In addition, I noticed rubygems fails to handle "304 Not
Modified" response.


$ gem update
Updating installed gems
ERROR:  While executing gem ... (URI::InvalidURIError)
    bad URI(is not URI?):


I think this is a problem of rubygems.
# users who live in GMT should know this bug, but I cannot
# find any report and complaint...  How come? :-(


Here is a patch.


Index: lib/rubygems/remote_fetcher.rb
===================================================================
--- lib/rubygems/remote_fetcher.rb	(revision 18876)
+++ lib/rubygems/remote_fetcher.rb	(working copy)
@@ -140,6 +140,7 @@

   def fetch_path(uri, mtime = nil, head = false)
     data = open_uri_or_path(uri, mtime, head)
+    return data if data.empty?
     data = Gem.gunzip data if uri.to_s =~ /gz$/ and not head
     data
   rescue FetchError
@@ -243,6 +244,8 @@
     case response
     when Net::HTTPOK then
       head ? response : response.body
+    when Net::HTTPNotModified then
+      return ""
     when Net::HTTPRedirection then
       raise FetchError.new('too many redirects', uri) if depth > 10

@@ -274,7 +277,7 @@
     request.add_field 'Keep-Alive', '30'

     if last_modified then
-      request.add_field 'If-Modified-Since', last_modified.rfc2822
+      request.add_field 'If-Modified-Since', last_modified.dup.gmtime.rfc2822
     end

     connection = connection_for uri

-- 
Yusuke ENDOH <mame@tsg.ne.jp>

History

Updated by mame (Yusuke Endoh) over 3 years ago

Hi,

2008/8/27 Tanaka Akira <akr@fsij.org>:
>> This is because Apache, which rubyforge uses, seems to handle
>> If-Modified-Since field only when it is represented in GMT.
>> This is not a fault of rubygems, but I think it's better for
>> rubygems to convert last_modified in GMT.
>
> See HTTP-date definition of RFC 2616.

Aha, this is a fault of rubygems X-(

-- 
Yusuke ENDOH <mame@tsg.ne.jp>

Updated by drbrain (Eric Hodel) over 3 years ago

On Aug 26, 2008, at 10:13 AM, Yusuke ENDOH wrote:
> 2008/8/27 Tanaka Akira <akr@fsij.org>:
>>> This is because Apache, which rubyforge uses, seems to handle
>>> If-Modified-Since field only when it is represented in GMT.
>>> This is not a fault of rubygems, but I think it's better for
>>> rubygems to convert last_modified in GMT.
>>
>> See HTTP-date definition of RFC 2616.
>
> Aha, this is a fault of rubygems X-(

I already fixed this in RubyGems trunk, but haven't got RubyGems  
stable enough to merge.

Updated by ko1 (Koichi Sasada) over 3 years ago

  • Assignee set to drbrain (Eric Hodel)

Updated by yugui (Yuki Sonoda) over 3 years ago

  • Target version set to 1.9.1 Release Candidate

Updated by yugui (Yuki Sonoda) over 3 years ago

  • Due date set to 11/25/2008
  • Category set to lib

Updated by yugui (Yuki Sonoda) over 3 years ago

I'll ask Eric whether it has already been merged.

Updated by drbrain (Eric Hodel) over 3 years ago

  • Status changed from Open to Closed
This has been fixed and merged.

Also available in: Atom PDF