mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge branch 'master' of git@github.com:rails/rails
This commit is contained in:
commit
0d48408dcc
5 changed files with 19 additions and 5 deletions
|
@ -587,7 +587,7 @@ module ActionController
|
|||
def response_from_page_or_rjs()
|
||||
content_type = @response.content_type
|
||||
|
||||
if content_type && content_type =~ /text\/javascript/
|
||||
if content_type && Mime::JS =~ content_type
|
||||
body = @response.body.dup
|
||||
root = HTML::Node.new(nil)
|
||||
|
||||
|
|
|
@ -227,9 +227,7 @@ module ActionController
|
|||
def xml_http_request(request_method, path, parameters = nil, headers = nil)
|
||||
headers ||= {}
|
||||
headers['X-Requested-With'] = 'XMLHttpRequest'
|
||||
headers['Accept'] ||= 'text/javascript, text/html, application/xml, ' +
|
||||
'text/xml, */*'
|
||||
|
||||
headers['Accept'] ||= [Mime::JS, Mime::HTML, Mime::XML, 'text/xml', Mime::ALL].join(', ')
|
||||
process(request_method, path, parameters, headers)
|
||||
end
|
||||
alias xhr :xml_http_request
|
||||
|
|
|
@ -176,6 +176,14 @@ module Mime
|
|||
end
|
||||
end
|
||||
|
||||
def =~(mime_type)
|
||||
return false if mime_type.blank?
|
||||
regexp = Regexp.new(mime_type.to_s)
|
||||
(@synonyms + [ self ]).any? do |synonym|
|
||||
synonym.to_s =~ regexp
|
||||
end
|
||||
end
|
||||
|
||||
# Returns true if Action Pack should check requests using this Mime Type for possible request forgery. See
|
||||
# ActionController::RequestForgeryProtection.
|
||||
def verify_request?
|
||||
|
|
|
@ -413,7 +413,7 @@ module ActionController #:nodoc:
|
|||
|
||||
def xml_http_request(request_method, action, parameters = nil, session = nil, flash = nil)
|
||||
@request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
|
||||
@request.env['HTTP_ACCEPT'] = 'text/javascript, text/html, application/xml, text/xml, */*'
|
||||
@request.env['HTTP_ACCEPT'] = [Mime::JS, Mime::HTML, Mime::XML, 'text/xml', Mime::ALL].join(', ')
|
||||
returning __send__(request_method, action, parameters, session, flash) do
|
||||
@request.env.delete 'HTTP_X_REQUESTED_WITH'
|
||||
@request.env.delete 'HTTP_ACCEPT'
|
||||
|
|
|
@ -81,4 +81,12 @@ class MimeTypeTest < Test::Unit::TestCase
|
|||
assert verified.each { |type| assert Mime.const_get(type.to_s.upcase).verify_request?, "Verifiable Mime Type is not verified: #{type.inspect}" }
|
||||
assert unverified.each { |type| assert !Mime.const_get(type.to_s.upcase).verify_request?, "Nonverifiable Mime Type is verified: #{type.inspect}" }
|
||||
end
|
||||
|
||||
def test_regexp_matcher
|
||||
assert Mime::JS =~ "text/javascript"
|
||||
assert Mime::JS =~ "application/javascript"
|
||||
assert Mime::JS !~ "text/html"
|
||||
assert !(Mime::JS !~ "text/javascript")
|
||||
assert !(Mime::JS !~ "application/javascript")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue