Case sensitive content_type "image/jpg" bug?

I encountered this problem while working with attachment_fu.

Simply stated, follow the attachment_fu README to set up the minimum
"Mugshot" model, controller, and views.

mugshot.rb

class Mugshot < ActiveRecord::Base
  has_attachment :content_type => :image,
                 :storage => :file_system,
                 :size => 0..3.megabytes,
                 :resize_to => '640x480>',
                 :thumbnails => { :thumb => '100x100>' }

  validates_as_attachment

end

..._create_mugshots.rb:

class CreateMugshots < ActiveRecord::Migration
  def self.up
    create_table :mugshots do |t|
      t.column :parent_id, :integer
      t.column :content_type, :string
      t.column :filename, :string
      t.column :thumbnail, :string
      t.column :size, :integer
      t.column :width, :integer
      t.column :height, :integer

      t.timestamps
    end
  end

  def self.down
    drop_table :mugshots
  end
end

mugshots_controller.rb:

  def index
    @mugshots = Mugshot.find(:all,
                             :conditions => {:thumbnail => nil})

    respond_to do |format|
      format.html # index.html.erb
      format.xml { render :xml => @mugshots }
    end
  end

views/mugshots/index.html.erb:

<h1>Most Wanted</h1>
<% for mugshot in @mugshots -%>
  <%= link_to image_tag(mugshot.public_filename(:thumb)),
      mugshot.public_filename %>
<% end -%>
<p>
  <%= link_to('New shot', { :action => 'new' }) %>
</p>

I added two images, "DSCN0925.jpg" and "DSCN0913.JPG" through the
application. The unix file command for these images tells me:

DSCN0913.JPG: JPEG image data, EXIF standard 2.2
DSCN0925.jpg: JPEG image data, EXIF standard 2.2

And, using script/console, Mugshot.find(:all) gives:

Mugshot.find(:all)

=> [#<Mugshot id: 1, parent_id: nil, content_type: "image/jpeg",
filename: "DSCN0925.jpg", thumbnail: nil, size: 818302, width: 640,
height: 479, created_at: "2009-04-29 19:01:17", updated_at:
"2009-04-29 19:01:17">, #<Mugshot id: 2, parent_id: 1, content_type:
"image/jpeg", filename: "DSCN0925_thumb.jpg", thumbnail: "thumb",
size: 75300, width: 100, height: 75, created_at: "2009-04-29
19:01:18", updated_at: "2009-04-29 19:01:18">, #<Mugshot id: 3,
parent_id: nil, content_type: "image/jpeg", filename: "DSCN0913.JPG",
thumbnail: nil, size: 833312, width: 640, height: 479, created_at:
"2009-04-29 19:01:48", updated_at: "2009-04-29 19:01:48">, #<Mugshot
id: 4, parent_id: 3, content_type: "image/jpeg", filename:
"DSCN0913_thumb.JPG", thumbnail: "thumb", size: 162513, width: 100,
height: 75, created_at: "2009-04-29 19:01:49", updated_at: "2009-04-29
19:01:49">]

NOTE: content_type for all four records is image/jpeg.

Observing the headers associated with a load of the view/mugshots/
index.html.erb view with Live HTTP gives:

Is this a bug or a truly bizarre feature?

Your URLs to the images go straight through your webserver (thin in
this case). Doesn't touch rails at all.

I'm guessing it's either a thin bug, or mis-configuration.

OK, so if it's a bug it exists in thin, webrick, and mongrel as all
three demonstrate the same behavior. Do you know if they share code?

It's more likely a misconfiguration as I am not doing anything to
configure these three servers. Any pointers on where to start
learning how would be appreciated.

thanks

Things to check:

Are you running this on a case sensitive file system?

Looking at the rack lib/rack/mime.rb, it only has the lowercase
versions of the extensions. I haven't looked deeply, but it is
possible that the code isn't doing the correct comparison of the
extension.

That rack file has instructions for adding additional mime types, so
if nothing else, you should try adding JPG.

Ray

Thanks for the pointer...

It took a bit of work as the comments in rack lib/rack/mime.rb were
almost right. FYI, here's what I ended up with that I've checked
with:

Ruby - 1.8.7 (2008-08-11 patchlevel 72) [powerpc-darwin9.6.0]
            1.9.2dev (2009-04-25 trunk 23281) [powerpc-darwin9.6.0]
Rails - 2.3.2
WEBrick - with ruby distribution
Thin - 1.0.0
Mongrel - 1.5.1 (Ruby 1.8 only)

RAILS_ROOT/config/initializers/mime_types.rb