Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

AC::Request#content_type should return a string

#2564

Today, I git pulled rails 2-3-stable and (inadvertently) updated rack to 1.0.0, therefore I can definitely tell who's at fault, it might even be me. Anyway, Rack::Request#media_type expects #content_type to return a string which it may not always do in its current incarnation. Below I've added in the tiny #to_s

ActionController::Request < Rack::Request


    def content_type
      @content_type ||= begin
        if @env['CONTENT_TYPE'] =~ /^([^,\;]*)/
          Mime::Type.lookup($1.strip.downcase).to_s
        else
          nil
        end
      end
    end

This issue may affect other code at the intersection of ActionController and Rack. ActionController uses Mime::Type objects freely, but Rack doesn't know about them.

Reported by Michael Schuerig · April 25th, 2009 @ 07:37 PM

State: resolved
Milestone: 2.x
Assigned to: josh josh
Importance: Low

Activity

  1. Michael Schuerig
    Michael Schuerig

    I just found out that the solution isn't that easy. It just blows up in another place, namely in request verification where it is assumed that request.content_type is a Mime::Type

    
    def verifiable_request_format?
      !request.content_type.nil? && request.content_type.verify_request?
    end
    

    The easiest solution would be to have Rack call #to_s on whatever it gets from Rack::Request#content_type.

    April 25th, 2009 @ 09:52 PM

  2. CancelProfileIsBroken
    CancelProfileIsBroken

    Is this still a problem if you pull 2-3-stable now? Bundled rack was just removed a couple of hours ago, and a few other changes to accommodate the Rack release. Just want to be sure before anyone goes digging.

    April 25th, 2009 @ 10:31 PM

  3. Michael Schuerig
    Michael Schuerig

    That one bows up instantly as there are still references to ActionController::RewindableInput which doesn't exist anymore.

    April 25th, 2009 @ 10:49 PM

  4. CancelProfileIsBroken
    CancelProfileIsBroken
    • Assigned user set to josh

    Looks like yours, Josh. Confirmed that AC is still attempting to autoload RewindableInput on 2-3-stable.

    April 25th, 2009 @ 11:30 PM

  5. Hongli Lai
  6. josh
    josh
    • State changed from new to resolved

    April 26th, 2009 @ 05:20 PM

  7. Bill
    Bill

    This worked for me- modifying my code to match the patches did not .

    (in initializers/mime_fix.rb) module Mime

    class Type
      def split(*args)
        to_s.split(*args)
      end
    end
    

    end

    May 14th, 2009 @ 05:03 AM

  8. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.
    • Importance changed from to Low

    Automatic cleanup of spam.

    November 8th, 2010 @ 08:50 AM