Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 3847

Show
Ignore:
Timestamp:
03/12/06 16:03:44 (3 years ago)
Author:
david
Message:

Mime types are separated by a comma, not semicolon, in the Accept header. Also switch all internal configuration of mime types away from strings and over to Mime::Type [DHH]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/lib/action_controller/base.rb

    r3838 r3847  
    272272    # Example of doing your own parser for a custom content type: 
    273273    # 
    274     #   ActionController::Base.param_parsers['application/atom+xml'] = Proc.new do |data|  
     274    #   ActionController::Base.param_parsers[Mime::Type.lookup('application/atom+xml')] = Proc.new do |data|  
    275275    #      node = REXML::Document.new(post)  
    276276    #     { node.root.name => node.root } 
     
    282282    # re-register XmlSimple as application/xml handler and enable application/x-yaml like this: 
    283283    # 
    284     #   ActionController::Base.param_parsers['application/xml']    =  
     284    #   ActionController::Base.param_parsers[Mime::XML]  =  
    285285    #     Proc.new { |data| XmlSimple.xml_in(data, 'ForceArray' => false) } 
    286     #   ActionController::Base.param_parsers['application/x-yaml'] = :yaml 
    287     @@param_parsers = { 'application/xml' => :xml_simple } 
     286    #   ActionController::Base.param_parsers[Mime::YAML] = :yaml 
     287    @@param_parsers = { Mime::XML => :xml_simple } 
    288288    cattr_accessor :param_parsers  
    289289 
  • trunk/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb

    r3808 r3847  
    5959    end 
    6060 
    61     def self.parse_formatted_request_parameters(format, raw_post_data) 
    62       params = case strategy = ActionController::Base.param_parsers[format
     61    def self.parse_formatted_request_parameters(mime_type, raw_post_data) 
     62      params = case strategy = ActionController::Base.param_parsers[mime_type
    6363        when Proc 
    6464          strategy.call(raw_post_data) 
  • trunk/actionpack/lib/action_controller/deprecated_request_methods.rb

    r3777 r3847  
    77    # X-Post-Data-Format HTTP header if present. 
    88    def post_format 
    9       case content_type 
     9      case content_type.to_s 
    1010      when 'application/xml' 
    1111        :xml 
  • trunk/actionpack/lib/action_controller/mime_type.rb

    r3844 r3847  
    11module Mime 
    2   class Type < String 
     2  class Type 
    33    def self.lookup(string) 
    44      LOOKUP[string] 
     
    77    def initialize(string, symbol = nil, synonyms = []) 
    88      @symbol, @synonyms = symbol, synonyms 
    9       super(string) 
     9      @string = string 
     10    end 
     11     
     12    def to_s 
     13      @string 
    1014    end 
    1115     
     
    2024        super 
    2125      end 
     26    end 
     27     
     28    def ==(mime_type) 
     29      (@synonyms + [ self ]).any? { |synonym| synonym.to_s == mime_type.to_s } if mime_type 
    2230    end 
    2331  end 
  • trunk/actionpack/lib/action_controller/request.rb

    r3844 r3847  
    7171        [ content_type, Mime::ALL ] 
    7272      else 
    73         @env['HTTP_ACCEPT'].split(";").collect! do |mime_type| 
    74           Mime::Type.lookup(mime_type.strip) 
     73        @env['HTTP_ACCEPT'].split(",").collect! do |mime_type| 
     74          Mime::Type.lookup(mime_type.split(";").first.strip) 
    7575        end 
    7676      end 
  • trunk/actionpack/lib/action_view/helpers/javascripts/prototype.js

    r3838 r3847  
    705705      ['X-Requested-With', 'XMLHttpRequest', 
    706706       'X-Prototype-Version', Prototype.Version, 
    707        'Accept', 'text/javascript; text/html; text/xml; */*' ]; 
     707       'Accept', 'text/javascript, text/xml, text/html, */*' ]; 
    708708 
    709709    if (this.options.method == 'post') { 
  • trunk/actionpack/test/controller/mime_responds_test.rb

    r3844 r3847  
    112112 
    113113  def test_js_or_html 
    114     @request.env["HTTP_ACCEPT"] = "text/javascript; text/html" 
     114    @request.env["HTTP_ACCEPT"] = "text/javascript, text/html" 
    115115    get :js_or_html 
    116116    assert_equal 'JS', @response.body 
     
    124124 
    125125  def test_js_or_anything 
    126     @request.env["HTTP_ACCEPT"] = "text/javascript; */*" 
     126    @request.env["HTTP_ACCEPT"] = "text/javascript, */*" 
    127127    get :js_or_html 
    128128    assert_equal 'JS', @response.body 
  • trunk/actionpack/test/controller/webservice_test.rb

    r3838 r3847  
    2929    @controller = TestController.new 
    3030    ActionController::Base.param_parsers.clear 
    31     ActionController::Base.param_parsers['application/xml'] = :xml_node 
     31    ActionController::Base.param_parsers[Mime::XML] = :xml_node 
    3232  end 
    3333   
     
    5656 
    5757  def test_register_and_use_yaml 
    58     ActionController::Base.param_parsers['application/x-yaml'] = Proc.new { |d| YAML.load(d) } 
     58    ActionController::Base.param_parsers[Mime::YAML] = Proc.new { |d| YAML.load(d) } 
    5959    process('POST', 'application/x-yaml', {"entry" => "loaded from yaml"}.to_yaml) 
    6060    assert_equal 'entry', @controller.response.body 
     
    6464   
    6565  def test_register_and_use_yaml_as_symbol 
    66     ActionController::Base.param_parsers['application/x-yaml'] = :yaml 
     66    ActionController::Base.param_parsers[Mime::YAML] = :yaml 
    6767    process('POST', 'application/x-yaml', {"entry" => "loaded from yaml"}.to_yaml) 
    6868    assert_equal 'entry', @controller.response.body 
     
    7272 
    7373  def test_register_and_use_xml_simple 
    74     ActionController::Base.param_parsers['application/xml'] = Proc.new { |data| XmlSimple.xml_in(data, 'ForceArray' => false) } 
     74    ActionController::Base.param_parsers[Mime::XML] = Proc.new { |data| XmlSimple.xml_in(data, 'ForceArray' => false) } 
    7575    process('POST', 'application/xml', '<request><summary>content...</summary><title>SimpleXml</title></request>' ) 
    7676    assert_equal 'summary, title', @controller.response.body 
     
    8383  def test_deprecated_request_methods 
    8484    process('POST', 'application/x-yaml') 
    85     assert_equal 'application/x-yaml', @controller.request.content_type 
     85    assert_equal Mime::YAML, @controller.request.content_type 
    8686    assert_equal true, @controller.request.post? 
    8787    assert_equal :yaml, @controller.request.post_format 
  • trunk/railties/html/javascripts/prototype.js

    r3845 r3847  
    705705      ['X-Requested-With', 'XMLHttpRequest', 
    706706       'X-Prototype-Version', Prototype.Version, 
    707        'Accept', 'text/javascript; text/html; text/xml; */*' ]; 
     707       'Accept', 'text/javascript, text/xml, text/html, */*' ]; 
    708708 
    709709    if (this.options.method == 'post') {