actionpack 4.2.8 → 5.2.4.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/CHANGELOG.md +285 -444
- data/MIT-LICENSE +1 -1
- data/README.rdoc +6 -7
- data/lib/abstract_controller.rb +12 -5
- data/lib/abstract_controller/asset_paths.rb +2 -0
- data/lib/abstract_controller/base.rb +45 -49
- data/lib/abstract_controller/caching.rb +66 -0
- data/lib/{action_controller → abstract_controller}/caching/fragments.rb +78 -15
- data/lib/abstract_controller/callbacks.rb +47 -31
- data/lib/abstract_controller/collector.rb +8 -11
- data/lib/abstract_controller/error.rb +6 -0
- data/lib/abstract_controller/helpers.rb +25 -25
- data/lib/abstract_controller/logger.rb +2 -0
- data/lib/abstract_controller/railties/routes_helpers.rb +4 -2
- data/lib/abstract_controller/rendering.rb +42 -41
- data/lib/abstract_controller/translation.rb +10 -7
- data/lib/abstract_controller/url_for.rb +2 -0
- data/lib/action_controller.rb +29 -21
- data/lib/action_controller/api.rb +149 -0
- data/lib/action_controller/api/api_rendering.rb +16 -0
- data/lib/action_controller/base.rb +27 -19
- data/lib/action_controller/caching.rb +14 -57
- data/lib/action_controller/form_builder.rb +50 -0
- data/lib/action_controller/log_subscriber.rb +10 -15
- data/lib/action_controller/metal.rb +98 -83
- data/lib/action_controller/metal/basic_implicit_render.rb +13 -0
- data/lib/action_controller/metal/conditional_get.rb +118 -44
- data/lib/action_controller/metal/content_security_policy.rb +52 -0
- data/lib/action_controller/metal/cookies.rb +3 -3
- data/lib/action_controller/metal/data_streaming.rb +27 -46
- data/lib/action_controller/metal/etag_with_flash.rb +18 -0
- data/lib/action_controller/metal/etag_with_template_digest.rb +20 -13
- data/lib/action_controller/metal/exceptions.rb +8 -14
- data/lib/action_controller/metal/flash.rb +4 -3
- data/lib/action_controller/metal/force_ssl.rb +23 -21
- data/lib/action_controller/metal/head.rb +21 -19
- data/lib/action_controller/metal/helpers.rb +24 -14
- data/lib/action_controller/metal/http_authentication.rb +64 -57
- data/lib/action_controller/metal/implicit_render.rb +62 -8
- data/lib/action_controller/metal/instrumentation.rb +19 -21
- data/lib/action_controller/metal/live.rb +90 -106
- data/lib/action_controller/metal/mime_responds.rb +33 -46
- data/lib/action_controller/metal/parameter_encoding.rb +51 -0
- data/lib/action_controller/metal/params_wrapper.rb +61 -53
- data/lib/action_controller/metal/redirecting.rb +49 -28
- data/lib/action_controller/metal/renderers.rb +87 -44
- data/lib/action_controller/metal/rendering.rb +72 -50
- data/lib/action_controller/metal/request_forgery_protection.rb +203 -92
- data/lib/action_controller/metal/rescue.rb +9 -16
- data/lib/action_controller/metal/streaming.rb +12 -10
- data/lib/action_controller/metal/strong_parameters.rb +582 -165
- data/lib/action_controller/metal/testing.rb +2 -17
- data/lib/action_controller/metal/url_for.rb +19 -10
- data/lib/action_controller/railtie.rb +28 -10
- data/lib/action_controller/railties/helpers.rb +2 -0
- data/lib/action_controller/renderer.rb +117 -0
- data/lib/action_controller/template_assertions.rb +11 -0
- data/lib/action_controller/test_case.rb +280 -411
- data/lib/action_dispatch.rb +27 -19
- data/lib/action_dispatch/http/cache.rb +93 -47
- data/lib/action_dispatch/http/content_security_policy.rb +272 -0
- data/lib/action_dispatch/http/filter_parameters.rb +26 -20
- data/lib/action_dispatch/http/filter_redirect.rb +10 -11
- data/lib/action_dispatch/http/headers.rb +55 -22
- data/lib/action_dispatch/http/mime_negotiation.rb +60 -41
- data/lib/action_dispatch/http/mime_type.rb +134 -121
- data/lib/action_dispatch/http/mime_types.rb +20 -6
- data/lib/action_dispatch/http/parameter_filter.rb +25 -11
- data/lib/action_dispatch/http/parameters.rb +98 -39
- data/lib/action_dispatch/http/rack_cache.rb +2 -0
- data/lib/action_dispatch/http/request.rb +200 -118
- data/lib/action_dispatch/http/response.rb +225 -110
- data/lib/action_dispatch/http/upload.rb +12 -6
- data/lib/action_dispatch/http/url.rb +110 -28
- data/lib/action_dispatch/journey.rb +7 -5
- data/lib/action_dispatch/journey/formatter.rb +55 -32
- data/lib/action_dispatch/journey/gtg/builder.rb +7 -5
- data/lib/action_dispatch/journey/gtg/simulator.rb +3 -9
- data/lib/action_dispatch/journey/gtg/transition_table.rb +17 -16
- data/lib/action_dispatch/journey/nfa/builder.rb +5 -3
- data/lib/action_dispatch/journey/nfa/dot.rb +13 -13
- data/lib/action_dispatch/journey/nfa/simulator.rb +3 -1
- data/lib/action_dispatch/journey/nfa/transition_table.rb +5 -48
- data/lib/action_dispatch/journey/nodes/node.rb +18 -6
- data/lib/action_dispatch/journey/parser.rb +23 -22
- data/lib/action_dispatch/journey/parser.y +3 -2
- data/lib/action_dispatch/journey/parser_extras.rb +12 -4
- data/lib/action_dispatch/journey/path/pattern.rb +50 -44
- data/lib/action_dispatch/journey/route.rb +106 -28
- data/lib/action_dispatch/journey/router.rb +35 -23
- data/lib/action_dispatch/journey/router/utils.rb +20 -11
- data/lib/action_dispatch/journey/routes.rb +18 -16
- data/lib/action_dispatch/journey/scanner.rb +18 -15
- data/lib/action_dispatch/journey/visitors.rb +99 -52
- data/lib/action_dispatch/middleware/callbacks.rb +1 -2
- data/lib/action_dispatch/middleware/cookies.rb +304 -193
- data/lib/action_dispatch/middleware/debug_exceptions.rb +152 -57
- data/lib/action_dispatch/middleware/debug_locks.rb +124 -0
- data/lib/action_dispatch/middleware/exception_wrapper.rb +68 -69
- data/lib/action_dispatch/middleware/executor.rb +21 -0
- data/lib/action_dispatch/middleware/flash.rb +78 -54
- data/lib/action_dispatch/middleware/public_exceptions.rb +27 -25
- data/lib/action_dispatch/middleware/reloader.rb +5 -91
- data/lib/action_dispatch/middleware/remote_ip.rb +41 -31
- data/lib/action_dispatch/middleware/request_id.rb +17 -9
- data/lib/action_dispatch/middleware/session/abstract_store.rb +41 -25
- data/lib/action_dispatch/middleware/session/cache_store.rb +24 -14
- data/lib/action_dispatch/middleware/session/cookie_store.rb +72 -67
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +8 -2
- data/lib/action_dispatch/middleware/show_exceptions.rb +26 -22
- data/lib/action_dispatch/middleware/ssl.rb +114 -36
- data/lib/action_dispatch/middleware/stack.rb +31 -44
- data/lib/action_dispatch/middleware/static.rb +57 -50
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +2 -14
- data/lib/action_dispatch/middleware/templates/rescues/{_source.erb → _source.html.erb} +0 -0
- data/lib/action_dispatch/middleware/templates/rescues/_source.text.erb +8 -0
- data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +21 -0
- data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +13 -0
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +1 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +1 -1
- data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +4 -4
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +64 -64
- data/lib/action_dispatch/railtie.rb +19 -11
- data/lib/action_dispatch/request/session.rb +106 -59
- data/lib/action_dispatch/request/utils.rb +67 -24
- data/lib/action_dispatch/routing.rb +17 -18
- data/lib/action_dispatch/routing/endpoint.rb +9 -2
- data/lib/action_dispatch/routing/inspector.rb +58 -67
- data/lib/action_dispatch/routing/mapper.rb +734 -447
- data/lib/action_dispatch/routing/polymorphic_routes.rb +161 -139
- data/lib/action_dispatch/routing/redirection.rb +36 -26
- data/lib/action_dispatch/routing/route_set.rb +321 -291
- data/lib/action_dispatch/routing/routes_proxy.rb +32 -5
- data/lib/action_dispatch/routing/url_for.rb +65 -25
- data/lib/action_dispatch/system_test_case.rb +147 -0
- data/lib/action_dispatch/system_testing/browser.rb +49 -0
- data/lib/action_dispatch/system_testing/driver.rb +59 -0
- data/lib/action_dispatch/system_testing/server.rb +31 -0
- data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +96 -0
- data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +31 -0
- data/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb +26 -0
- data/lib/action_dispatch/testing/assertion_response.rb +47 -0
- data/lib/action_dispatch/testing/assertions.rb +6 -4
- data/lib/action_dispatch/testing/assertions/response.rb +45 -20
- data/lib/action_dispatch/testing/assertions/routing.rb +30 -26
- data/lib/action_dispatch/testing/integration.rb +347 -209
- data/lib/action_dispatch/testing/request_encoder.rb +55 -0
- data/lib/action_dispatch/testing/test_process.rb +28 -22
- data/lib/action_dispatch/testing/test_request.rb +27 -34
- data/lib/action_dispatch/testing/test_response.rb +35 -7
- data/lib/action_pack.rb +4 -2
- data/lib/action_pack/gem_version.rb +5 -3
- data/lib/action_pack/version.rb +3 -1
- metadata +56 -39
- data/lib/action_controller/metal/hide_actions.rb +0 -40
- data/lib/action_controller/metal/rack_delegation.rb +0 -32
- data/lib/action_controller/middleware.rb +0 -39
- data/lib/action_controller/model_naming.rb +0 -12
- data/lib/action_dispatch/journey/backwards.rb +0 -5
- data/lib/action_dispatch/journey/router/strexp.rb +0 -27
- data/lib/action_dispatch/middleware/params_parser.rb +0 -60
- data/lib/action_dispatch/testing/assertions/dom.rb +0 -3
- data/lib/action_dispatch/testing/assertions/selector.rb +0 -3
- data/lib/action_dispatch/testing/assertions/tag.rb +0 -3
@@ -1,23 +1,34 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# -*- frozen-string-literal: true -*-
|
4
|
+
|
5
|
+
require "singleton"
|
6
|
+
require "active_support/core_ext/string/starts_ends_with"
|
5
7
|
|
6
8
|
module Mime
|
7
|
-
class Mimes
|
8
|
-
|
9
|
-
|
9
|
+
class Mimes
|
10
|
+
include Enumerable
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@mimes = []
|
14
|
+
@symbols = nil
|
10
15
|
end
|
11
16
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def each
|
18
|
+
@mimes.each { |x| yield x }
|
19
|
+
end
|
20
|
+
|
21
|
+
def <<(type)
|
22
|
+
@mimes << type
|
23
|
+
@symbols = nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete_if
|
27
|
+
@mimes.delete_if { |x| yield x }.tap { @symbols = nil }
|
28
|
+
end
|
29
|
+
|
30
|
+
def symbols
|
31
|
+
@symbols ||= map(&:to_sym)
|
21
32
|
end
|
22
33
|
end
|
23
34
|
|
@@ -37,7 +48,7 @@ module Mime
|
|
37
48
|
end
|
38
49
|
end
|
39
50
|
|
40
|
-
# Encapsulates the notion of a
|
51
|
+
# Encapsulates the notion of a MIME type. Can be used at render time, for example, with:
|
41
52
|
#
|
42
53
|
# class PostsController < ActionController::Base
|
43
54
|
# def show
|
@@ -45,20 +56,17 @@ module Mime
|
|
45
56
|
#
|
46
57
|
# respond_to do |format|
|
47
58
|
# format.html
|
48
|
-
# format.ics { render
|
59
|
+
# format.ics { render body: @post.to_ics, mime_type: Mime::Type.lookup("text/calendar") }
|
49
60
|
# format.xml { render xml: @post }
|
50
61
|
# end
|
51
62
|
# end
|
52
63
|
# end
|
53
64
|
class Type
|
54
|
-
@@html_types = Set.new [:html, :all]
|
55
|
-
cattr_reader :html_types
|
56
|
-
|
57
65
|
attr_reader :symbol
|
58
66
|
|
59
67
|
@register_callbacks = []
|
60
68
|
|
61
|
-
# A simple helper class used in parsing the accept header
|
69
|
+
# A simple helper class used in parsing the accept header.
|
62
70
|
class AcceptItem #:nodoc:
|
63
71
|
attr_accessor :index, :name, :q
|
64
72
|
alias :to_s :name
|
@@ -66,7 +74,7 @@ module Mime
|
|
66
74
|
def initialize(index, name, q = nil)
|
67
75
|
@index = index
|
68
76
|
@name = name
|
69
|
-
q ||= 0.0 if @name ==
|
77
|
+
q ||= 0.0 if @name == "*/*".freeze # Default wildcard match to end of list.
|
70
78
|
@q = ((q || 1.0).to_f * 100).to_i
|
71
79
|
end
|
72
80
|
|
@@ -75,70 +83,58 @@ module Mime
|
|
75
83
|
result = @index <=> item.index if result == 0
|
76
84
|
result
|
77
85
|
end
|
78
|
-
|
79
|
-
def ==(item)
|
80
|
-
@name == item.to_s
|
81
|
-
end
|
82
86
|
end
|
83
87
|
|
84
|
-
class AcceptList
|
85
|
-
def
|
86
|
-
sort!
|
88
|
+
class AcceptList #:nodoc:
|
89
|
+
def self.sort!(list)
|
90
|
+
list.sort!
|
87
91
|
|
88
|
-
|
92
|
+
text_xml_idx = find_item_by_name list, "text/xml"
|
93
|
+
app_xml_idx = find_item_by_name list, Mime[:xml].to_s
|
94
|
+
|
95
|
+
# Take care of the broken text/xml entry by renaming or deleting it.
|
89
96
|
if text_xml_idx && app_xml_idx
|
90
|
-
app_xml
|
91
|
-
|
92
|
-
|
97
|
+
app_xml = list[app_xml_idx]
|
98
|
+
text_xml = list[text_xml_idx]
|
99
|
+
|
100
|
+
app_xml.q = [text_xml.q, app_xml.q].max # Set the q value to the max of the two.
|
101
|
+
if app_xml_idx > text_xml_idx # Make sure app_xml is ahead of text_xml in the list.
|
102
|
+
list[app_xml_idx], list[text_xml_idx] = text_xml, app_xml
|
103
|
+
app_xml_idx, text_xml_idx = text_xml_idx, app_xml_idx
|
104
|
+
end
|
105
|
+
list.delete_at(text_xml_idx) # Delete text_xml from the list.
|
93
106
|
elsif text_xml_idx
|
94
|
-
|
107
|
+
list[text_xml_idx].name = Mime[:xml].to_s
|
95
108
|
end
|
96
109
|
|
97
|
-
# Look for more specific XML-based types and sort them ahead of app/xml
|
110
|
+
# Look for more specific XML-based types and sort them ahead of app/xml.
|
98
111
|
if app_xml_idx
|
112
|
+
app_xml = list[app_xml_idx]
|
99
113
|
idx = app_xml_idx
|
100
114
|
|
101
|
-
while idx < length
|
102
|
-
type =
|
115
|
+
while idx < list.length
|
116
|
+
type = list[idx]
|
103
117
|
break if type.q < app_xml.q
|
104
118
|
|
105
|
-
if type.name.ends_with?
|
106
|
-
|
107
|
-
|
119
|
+
if type.name.ends_with? "+xml"
|
120
|
+
list[app_xml_idx], list[idx] = list[idx], app_xml
|
121
|
+
app_xml_idx = idx
|
108
122
|
end
|
109
123
|
idx += 1
|
110
124
|
end
|
111
125
|
end
|
112
126
|
|
113
|
-
map! { |i| Mime::Type.lookup(i.name) }.uniq!
|
114
|
-
|
127
|
+
list.map! { |i| Mime::Type.lookup(i.name) }.uniq!
|
128
|
+
list
|
115
129
|
end
|
116
130
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
|
-
def app_xml_idx
|
123
|
-
@app_xml_idx ||= index(Mime::XML.to_s)
|
124
|
-
end
|
125
|
-
|
126
|
-
def text_xml
|
127
|
-
self[text_xml_idx]
|
128
|
-
end
|
129
|
-
|
130
|
-
def app_xml
|
131
|
-
self[app_xml_idx]
|
132
|
-
end
|
133
|
-
|
134
|
-
def exchange_xml_items
|
135
|
-
self[app_xml_idx], self[text_xml_idx] = text_xml, app_xml
|
136
|
-
@app_xml_idx, @text_xml_idx = text_xml_idx, app_xml_idx
|
137
|
-
end
|
131
|
+
def self.find_item_by_name(array, name)
|
132
|
+
array.index { |item| item.name == name }
|
133
|
+
end
|
138
134
|
end
|
139
135
|
|
140
136
|
class << self
|
141
|
-
TRAILING_STAR_REGEXP =
|
137
|
+
TRAILING_STAR_REGEXP = /^(text|application)\/\*/
|
142
138
|
PARAMETER_SEPARATOR_REGEXP = /;\s*\w+="?\w+"?/
|
143
139
|
|
144
140
|
def register_callback(&block)
|
@@ -153,46 +149,47 @@ module Mime
|
|
153
149
|
EXTENSION_LOOKUP[extension.to_s]
|
154
150
|
end
|
155
151
|
|
156
|
-
# Registers an alias that's not used on
|
152
|
+
# Registers an alias that's not used on MIME type lookup, but can be referenced directly. Especially useful for
|
157
153
|
# rendering different HTML versions depending on the user agent, like an iPhone.
|
158
154
|
def register_alias(string, symbol, extension_synonyms = [])
|
159
155
|
register(string, symbol, [], extension_synonyms, true)
|
160
156
|
end
|
161
157
|
|
162
158
|
def register(string, symbol, mime_type_synonyms = [], extension_synonyms = [], skip_lookup = false)
|
163
|
-
|
159
|
+
new_mime = Type.new(string, symbol, mime_type_synonyms)
|
164
160
|
|
165
|
-
new_mime = Mime.const_get(symbol.upcase)
|
166
161
|
SET << new_mime
|
167
162
|
|
168
|
-
([string] + mime_type_synonyms).each { |str| LOOKUP[str] =
|
169
|
-
([symbol] + extension_synonyms).each { |ext| EXTENSION_LOOKUP[ext.to_s] =
|
163
|
+
([string] + mime_type_synonyms).each { |str| LOOKUP[str] = new_mime } unless skip_lookup
|
164
|
+
([symbol] + extension_synonyms).each { |ext| EXTENSION_LOOKUP[ext.to_s] = new_mime }
|
170
165
|
|
171
166
|
@register_callbacks.each do |callback|
|
172
167
|
callback.call(new_mime)
|
173
168
|
end
|
169
|
+
new_mime
|
174
170
|
end
|
175
171
|
|
176
172
|
def parse(accept_header)
|
177
|
-
if !accept_header.include?(
|
173
|
+
if !accept_header.include?(",")
|
178
174
|
accept_header = accept_header.split(PARAMETER_SEPARATOR_REGEXP).first
|
179
175
|
parse_trailing_star(accept_header) || [Mime::Type.lookup(accept_header)].compact
|
180
176
|
else
|
181
|
-
list, index =
|
182
|
-
accept_header.split(
|
177
|
+
list, index = [], 0
|
178
|
+
accept_header.split(",").each do |header|
|
183
179
|
params, q = header.split(PARAMETER_SEPARATOR_REGEXP)
|
184
|
-
if params.present?
|
185
|
-
params.strip!
|
186
180
|
|
187
|
-
|
181
|
+
next unless params
|
182
|
+
params.strip!
|
183
|
+
next if params.empty?
|
188
184
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
185
|
+
params = parse_trailing_star(params) || [params]
|
186
|
+
|
187
|
+
params.each do |m|
|
188
|
+
list << AcceptItem.new(index, m.to_s, q)
|
189
|
+
index += 1
|
193
190
|
end
|
194
191
|
end
|
195
|
-
|
192
|
+
AcceptList.sort! list
|
196
193
|
end
|
197
194
|
end
|
198
195
|
|
@@ -200,28 +197,27 @@ module Mime
|
|
200
197
|
parse_data_with_trailing_star($1) if accept_header =~ TRAILING_STAR_REGEXP
|
201
198
|
end
|
202
199
|
|
203
|
-
# For an input of <tt>'text'</tt>, returns <tt>[Mime
|
204
|
-
# Mime
|
200
|
+
# For an input of <tt>'text'</tt>, returns <tt>[Mime[:json], Mime[:xml], Mime[:ics],
|
201
|
+
# Mime[:html], Mime[:css], Mime[:csv], Mime[:js], Mime[:yaml], Mime[:text]</tt>.
|
205
202
|
#
|
206
|
-
# For an input of <tt>'application'</tt>, returns <tt>[Mime
|
207
|
-
# Mime
|
208
|
-
def parse_data_with_trailing_star(
|
209
|
-
Mime::SET.select { |m| m =~
|
203
|
+
# For an input of <tt>'application'</tt>, returns <tt>[Mime[:html], Mime[:js],
|
204
|
+
# Mime[:xml], Mime[:yaml], Mime[:atom], Mime[:json], Mime[:rss], Mime[:url_encoded_form]</tt>.
|
205
|
+
def parse_data_with_trailing_star(type)
|
206
|
+
Mime::SET.select { |m| m =~ type }
|
210
207
|
end
|
211
208
|
|
212
209
|
# This method is opposite of register method.
|
213
210
|
#
|
214
|
-
#
|
211
|
+
# To unregister a MIME type:
|
215
212
|
#
|
216
213
|
# Mime::Type.unregister(:mobile)
|
217
214
|
def unregister(symbol)
|
218
|
-
symbol = symbol.
|
219
|
-
mime = Mime
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
EXTENSION_LOOKUP.delete_if { |_,v| v.eql?(mime) }
|
215
|
+
symbol = symbol.downcase
|
216
|
+
if mime = Mime[symbol]
|
217
|
+
SET.delete_if { |v| v.eql?(mime) }
|
218
|
+
LOOKUP.delete_if { |_, v| v.eql?(mime) }
|
219
|
+
EXTENSION_LOOKUP.delete_if { |_, v| v.eql?(mime) }
|
220
|
+
end
|
225
221
|
end
|
226
222
|
end
|
227
223
|
|
@@ -246,7 +242,7 @@ module Mime
|
|
246
242
|
end
|
247
243
|
|
248
244
|
def ref
|
249
|
-
|
245
|
+
symbol || to_s
|
250
246
|
end
|
251
247
|
|
252
248
|
def ===(list)
|
@@ -258,7 +254,7 @@ module Mime
|
|
258
254
|
end
|
259
255
|
|
260
256
|
def ==(mime_type)
|
261
|
-
return false
|
257
|
+
return false unless mime_type
|
262
258
|
(@synonyms + [ self ]).any? do |synonym|
|
263
259
|
synonym.to_s == mime_type.to_s || synonym.to_sym == mime_type.to_sym
|
264
260
|
end
|
@@ -272,40 +268,57 @@ module Mime
|
|
272
268
|
end
|
273
269
|
|
274
270
|
def =~(mime_type)
|
275
|
-
return false
|
271
|
+
return false unless mime_type
|
276
272
|
regexp = Regexp.new(Regexp.quote(mime_type.to_s))
|
277
|
-
|
278
|
-
synonym.to_s =~ regexp
|
279
|
-
end
|
273
|
+
@synonyms.any? { |synonym| synonym.to_s =~ regexp } || @string =~ regexp
|
280
274
|
end
|
281
275
|
|
282
276
|
def html?
|
283
|
-
|
277
|
+
symbol == :html || @string =~ /html/
|
284
278
|
end
|
285
279
|
|
280
|
+
def all?; false; end
|
286
281
|
|
282
|
+
# TODO Change this to private once we've dropped Ruby 2.2 support.
|
283
|
+
# Workaround for Ruby 2.2 "private attribute?" warning.
|
287
284
|
protected
|
288
285
|
|
289
|
-
|
286
|
+
attr_reader :string, :synonyms
|
290
287
|
|
291
288
|
private
|
292
289
|
|
293
|
-
|
294
|
-
|
290
|
+
def to_ary; end
|
291
|
+
def to_a; end
|
295
292
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
293
|
+
def method_missing(method, *args)
|
294
|
+
if method.to_s.ends_with? "?"
|
295
|
+
method[0..-2].downcase.to_sym == to_sym
|
296
|
+
else
|
297
|
+
super
|
298
|
+
end
|
301
299
|
end
|
302
|
-
end
|
303
300
|
|
304
|
-
|
305
|
-
|
301
|
+
def respond_to_missing?(method, include_private = false)
|
302
|
+
(method.to_s.ends_with? "?") || super
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
class AllType < Type
|
307
|
+
include Singleton
|
308
|
+
|
309
|
+
def initialize
|
310
|
+
super "*/*", :all
|
306
311
|
end
|
312
|
+
|
313
|
+
def all?; true; end
|
314
|
+
def html?; true; end
|
307
315
|
end
|
308
316
|
|
317
|
+
# ALL isn't a real MIME type, so we don't register it for lookup with the
|
318
|
+
# other concrete types. It's a wildcard match that we use for `respond_to`
|
319
|
+
# negotiation internals.
|
320
|
+
ALL = AllType.instance
|
321
|
+
|
309
322
|
class NullType
|
310
323
|
include Singleton
|
311
324
|
|
@@ -315,15 +328,15 @@ module Mime
|
|
315
328
|
|
316
329
|
def ref; end
|
317
330
|
|
318
|
-
def respond_to_missing?(method, include_private = false)
|
319
|
-
method.to_s.ends_with? '?'
|
320
|
-
end
|
321
|
-
|
322
331
|
private
|
323
|
-
|
324
|
-
|
325
|
-
|
332
|
+
def respond_to_missing?(method, _)
|
333
|
+
method.to_s.ends_with? "?"
|
334
|
+
end
|
335
|
+
|
336
|
+
def method_missing(method, *args)
|
337
|
+
false if method.to_s.ends_with? "?"
|
338
|
+
end
|
326
339
|
end
|
327
340
|
end
|
328
341
|
|
329
|
-
require
|
342
|
+
require "action_dispatch/http/mime_types"
|
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Build list of Mime types for HTTP responses
|
2
|
-
#
|
4
|
+
# https://www.iana.org/assignments/media-types/
|
3
5
|
|
4
6
|
Mime::Type.register "text/html", :html, %w( application/xhtml+xml ), %w( xhtml )
|
5
7
|
Mime::Type.register "text/plain", :text, [], %w(txt)
|
@@ -8,29 +10,41 @@ Mime::Type.register "text/css", :css
|
|
8
10
|
Mime::Type.register "text/calendar", :ics
|
9
11
|
Mime::Type.register "text/csv", :csv
|
10
12
|
Mime::Type.register "text/vcard", :vcf
|
13
|
+
Mime::Type.register "text/vtt", :vtt, %w(vtt)
|
11
14
|
|
12
15
|
Mime::Type.register "image/png", :png, [], %w(png)
|
13
16
|
Mime::Type.register "image/jpeg", :jpeg, [], %w(jpg jpeg jpe pjpeg)
|
14
17
|
Mime::Type.register "image/gif", :gif, [], %w(gif)
|
15
18
|
Mime::Type.register "image/bmp", :bmp, [], %w(bmp)
|
16
19
|
Mime::Type.register "image/tiff", :tiff, [], %w(tif tiff)
|
20
|
+
Mime::Type.register "image/svg+xml", :svg
|
17
21
|
|
18
22
|
Mime::Type.register "video/mpeg", :mpeg, [], %w(mpg mpeg mpe)
|
19
23
|
|
24
|
+
Mime::Type.register "audio/mpeg", :mp3, [], %w(mp1 mp2 mp3)
|
25
|
+
Mime::Type.register "audio/ogg", :ogg, [], %w(oga ogg spx opus)
|
26
|
+
Mime::Type.register "audio/aac", :m4a, %w( audio/mp4 ), %w(m4a mpg4 aac)
|
27
|
+
|
28
|
+
Mime::Type.register "video/webm", :webm, [], %w(webm)
|
29
|
+
Mime::Type.register "video/mp4", :mp4, [], %w(mp4 m4v)
|
30
|
+
|
31
|
+
Mime::Type.register "font/otf", :otf, [], %w(otf)
|
32
|
+
Mime::Type.register "font/ttf", :ttf, [], %w(ttf)
|
33
|
+
Mime::Type.register "font/woff", :woff, [], %w(woff)
|
34
|
+
Mime::Type.register "font/woff2", :woff2, [], %w(woff2)
|
35
|
+
|
20
36
|
Mime::Type.register "application/xml", :xml, %w( text/xml application/x-xml )
|
21
37
|
Mime::Type.register "application/rss+xml", :rss
|
22
38
|
Mime::Type.register "application/atom+xml", :atom
|
23
|
-
Mime::Type.register "application/x-yaml", :yaml, %w( text/yaml )
|
39
|
+
Mime::Type.register "application/x-yaml", :yaml, %w( text/yaml ), %w(yml yaml)
|
24
40
|
|
25
41
|
Mime::Type.register "multipart/form-data", :multipart_form
|
26
42
|
Mime::Type.register "application/x-www-form-urlencoded", :url_encoded_form
|
27
43
|
|
28
|
-
#
|
44
|
+
# https://www.ietf.org/rfc/rfc4627.txt
|
29
45
|
# http://www.json.org/JSONRequest.html
|
30
46
|
Mime::Type.register "application/json", :json, %w( text/x-json application/jsonrequest )
|
31
47
|
|
32
48
|
Mime::Type.register "application/pdf", :pdf, [], %w(pdf)
|
33
49
|
Mime::Type.register "application/zip", :zip, [], %w(zip)
|
34
|
-
|
35
|
-
# Create Mime::ALL but do not add it to the SET.
|
36
|
-
Mime::ALL = Mime::Type.new("*/*", :all, [])
|
50
|
+
Mime::Type.register "application/gzip", :gzip, %w(application/x-gzip), %w(gz)
|