aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/http/mime_type.rb
Commit message (Collapse)AuthorAgeFilesLines
* [Action Pack] require => require_relativeAkira Matsuda2017-10-211-1/+1
| | | | | This basically reverts e9fca7668b9eba82bcc832cb0061459703368397, d08da958b9ae17d4bbe4c9d7db497ece2450db5f, d1fe1dcf8ab1c0210a37c2a78c1ee52cf199a66d, and 68eaf7b4d5f2bb56d939f71c5ece2d61cf6680a3
* Use frozen string literal in actionpack/Kir Shatrov2017-07-291-0/+2
|
* [Action Dispatch] require => require_relativeAkira Matsuda2017-07-011-1/+1
|
* `respond_to_missing?` should be privateRyuta Kamizono2017-04-221-4/+4
| | | | | | | Follow up of 03d3f036. Some of `respond_to?` were replaced to `respond_to_missing?` in 03d3f036. But the visibility is still public. It should be private.
* [docs] fix ActionDispatch documentationHrvoje Šimić2017-03-131-9/+9
|
* Removed the `attribute_accessors` required file:Edouard CHIN2017-02-121-1/+0
| | | | - This file is no more needed, the call to `cattr_reader` were removed in https://github.com/rails/rails/commit/9e2948e750fa3f641f20adad4b4ecae89b35faa7#diff-c5146df11f35304765e9ceebed108f57L60 and https://github.com/rails/rails/commit/1fe0a1b5ebebb1372968606b85ce08b93bc145c8#diff-c5146df11f35304765e9ceebed108f57L99
* `respond_to_missing?` should fallback to `super` where method_missing could ↵Akira Matsuda2017-01-151-1/+1
| | | | call `super`
* No need to nodoc private methodsAkira Matsuda2016-12-241-1/+1
|
* Describe what we are protectingAkira Matsuda2016-12-231-0/+2
|
* Remove deprecated access to mime types through constantsRafael Mendonça França2016-10-101-26/+0
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-15/+15
|
* applies new string literal convention in actionpack/libXavier Noria2016-08-061-14/+14
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* speed up accept header parsing a bit.Aaron Patterson2016-01-281-8/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Accept header is taken from what Safari on El Capitan sends: ```ruby require 'benchmark/ips' require 'action_dispatch/http/mime_type' require 'active_support/all' accept = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' Benchmark.ips do |x| x.report "omg" do Mime::Type.parse(accept) end end ``` Before: ``` [aaron@TC actionpack (master)]$ be ruby ../x.rb Calculating ------------------------------------- omg 3.181k i/100ms ------------------------------------------------- omg 35.062k (±12.8%) i/s - 174.955k [aaron@TC actionpack (master)]$ be ruby ../x.rb Calculating ------------------------------------- omg 3.153k i/100ms ------------------------------------------------- omg 33.724k (±12.4%) i/s - 167.109k [aaron@TC actionpack (master)]$ be ruby ../x.rb Calculating ------------------------------------- omg 3.575k i/100ms ------------------------------------------------- omg 37.251k (±10.4%) i/s - 185.900k ``` After: ``` [aaron@TC actionpack (master)]$ be ruby ../x.rb Calculating ------------------------------------- omg 3.365k i/100ms ------------------------------------------------- omg 40.069k (±16.1%) i/s - 198.535k [aaron@TC actionpack (master)]$ be ruby ../x.rb Calculating ------------------------------------- omg 4.168k i/100ms ------------------------------------------------- omg 47.596k (± 7.7%) i/s - 237.576k [aaron@TC actionpack (master)]$ be ruby ../x.rb Calculating ------------------------------------- omg 4.282k i/100ms ------------------------------------------------- omg 43.626k (±17.7%) i/s - 209.818k ```
* convert AcceptList to a regular classAaron Patterson2016-01-281-20/+19
| | | | | | | we never use this custom array outside the mime type `parse` method. We can reduce the interaction to just a regular array, so we should use that instead (IOW, there was nothing special about AcceptList so we should remove it).
* remove == from AcceptItemAaron Patterson2016-01-271-6/+7
| | | | | | | | Remove nonsense definition of == from `AcceptItem`. The definition only compared names and not `q` values or even object identity. The only use was in the `assort!` method that really just wanted the index of the item given the item's name. Instead we just change the caller to use `index` with the block form.
* remove useless private methodsAaron Patterson2016-01-271-13/+9
| | | | | This commit refactors the private methods that were just aliases to [] to just directly use [] and cache the return values on the stack.
* change `@app_xml_idx` to an lvar and cache it on the stackAaron Patterson2016-01-271-16/+10
| | | | | same strategy as `@text_xml_idx`: cache it on the stack to avoid ivar lookups and the `||=` call.
* change `@text_xml_idx` to an lvar and cache it on the stackAaron Patterson2016-01-271-13/+11
| | | | | this eliminates the ivar lookup and also eliminates the `||=` conditional that happens every time we called the `text_xml_idx` method.
* stop caching mime types globallyAaron Patterson2016-01-221-2/+16
| | | | | | | Unknown mime types should not be cached globally. This global cache leads to a memory leak and a denial of service vulnerability. CVE-2016-0751
* Shrink a couple of deprecation warnings to one-linersMatthew Draper2015-12-061-18/+8
| | | | | The previous spelling seemed a bit too generous with the whitespace, and looked out of place when amongst others.
* Delete needless `require 'active_support/deprecation'`yui-knk2015-10-201-1/+0
| | | | | When `require 'active_support/rails'`, 'active_support/deprecation' is automatically loaded.
* Use `Mime[:foo]` instead of `Mime::Type[:FOO]` for back compatJeremy Daer2015-10-061-38/+36
| | | | | | | | | | | | | | | | | Rails 4.x and earlier didn't support `Mime::Type[:FOO]`, so libraries that support multiple Rails versions would've had to feature-detect whether to use `Mime::Type[:FOO]` or `Mime::FOO`. `Mime[:foo]` has been around for ages to look up registered MIME types by symbol / extension, though, so libraries and plugins can safely switch to that without breaking backward- or forward-compatibility. Note: `Mime::ALL` isn't a real MIME type and isn't registered for lookup by type or extension, so it's not available as `Mime[:all]`. We use it internally as a wildcard for `respond_to` negotiation. If you use this internal constant, continue to reference it with `Mime::ALL`. Ref. efc6dd550ee49e7e443f9d72785caa0f240def53
* Fix deprecated mime types via constantsamitkumarsuroliya2015-09-251-5/+5
| | | Accessing mime types via constants is deprecated. Now, we are using `Mime::Type[:JSON]` instead of `Mime::JSON`
* drop array allocations on Mime::Type#=~Aaron Patterson2015-09-211-3/+1
| | | | | Synonyms are always a list of strings, and we have access to the internal string representation, so we can avoid allocating new arrays.
* remove another `blank?` callAaron Patterson2015-09-211-1/+1
|
* remove html_types setAaron Patterson2015-09-211-6/+2
| | | | Now that `all` has it's own object, we don't need the html_types Set.
* introduce an `All` mime typeAaron Patterson2015-09-211-0/+6
| | | | | This class gives us the `all?` predicate method that returns true without hitting method missing
* remove `blank?` calls on `==`Aaron Patterson2015-09-211-1/+1
| | | | | | | | | Since Mime::Type implements `method_missing`, and `blank?` triggers it's positive branch: https://github.com/rails/rails/blob/f9dda1567ea8d5b27bd9d66ac5a8b43dc67a6b7e/actionpack/lib/action_dispatch/http/mime_type.rb#L342 We should stop calling `blank?`.
* change inheritance to compositionAaron Patterson2015-09-211-14/+24
| | | | | | Changes `Mimes` to compose a set rather than inherit from array. With this change we don't need to define as many methods, so ISEQ memory is saved. Also it is clear which methods break the set cache.
* stop calling deprecated methodsAaron Patterson2015-09-211-2/+2
| | | | | We should be asking the mime type method for the mime objects rather than via const lookup
* deprecate accessing mime types via constantsAaron Patterson2015-09-211-5/+53
| | | | | | | | | | | | | | | | | | We don't want to manage a list of constants on `Mime::`. Managing constants is strange because it will break method caches, not to mention looking up by a constant could cause troubles. For example suppose there is a top level constant `HTML`, but nobody registers the HTML mime type and someone accesses `Mime::HTML`. Instead of getting an error about how the mime type doesn't exist, instead you'll get the top level constant. So, instead of directly accessing the constants, change this: Mime::HTML To this: Mime::Type[:HTML]
* cache the new type object on the stackAaron Patterson2015-09-211-2/+2
| | | | Now we don't have to look it up with a `const_get`.
* Stop using deprecated `render :text` in testPrem Sichanugrist2015-07-171-1/+1
| | | | | | | | | This will silence deprecation warnings. Most of the test can be changed from `render :text` to render `:plain` or `render :body` right away. However, there are some tests that needed to be fixed by hand as they actually assert the default Content-Type returned from `render :body`.
* added description instead of remove usage [ci skip]Julio Lopez2015-07-111-1/+1
|
* fix method name in mime type example. `Mime::Type.[]` doesn't exist. [ci skip]yuuji.yaginuma2015-02-231-1/+1
|
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-1/+1
|
* [ci skip]Correct variables in the sample codesuginoy2014-09-101-2/+2
|
* Replace trivial regexp with string or index, twice as fastKelley Reynolds2014-03-281-1/+1
|
* Move the null mime type to request.formatCarlos Antonio da Silva2013-12-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | TLDR: always return an object that responds to the query methods from request.format, and do not touch Mime::Type[] lookup to avoid bugs. --- Long version: The initial issue was about being able to do checks like request.format.html? for request with an unknown format, where request.format would be nil. This is where the issue came from at first in #7837 and #8085 (merged in cba05887dc3b56a46a9fe2779b6b228880b49622), but the implementation went down the path of adding this to the mime type lookup logic. This unfortunately introduced subtle bugs, for instance in the merged commit a test related to send_file had to be changed to accomodate the introduction of the NullType. Later another bug was found in #13064, related to the content-type being shown as #<Mime::NullType:...> for templates with localized extensions but no format included. This one was fixed in #13133, merged in 43962d6ec50f918c9970bd3cd4b6ee5c7f7426ed. Besides that, custom handlers were not receiving the proper template formats anymore when passing through the rendering process, because of the NullType addition. That was found while migrating an application from 3.2 to 4.0 that uses the Markerb gem (a custom handler that generates both text and html emails from a markdown template). --- This changes the implementation moving away from returning this null object from the mime lookup, and still fixes the initial issue where request.format.zomg? would raise an exception for unknown formats due to request.format being nil.
* remove nil in NullType#ref.Angelo capilleri2013-12-041-3/+1
| | | | | Return Nil is implicit in a method and this syntax is used in the others classes
* Convert Mime::NullType in a singletonGuillermo Iguaran2013-12-031-1/+4
|
* Remove deprecated cattr_* requiresGenadi Samokovarov2013-12-031-1/+1
|
* Fix undefined method `ref' for nil:NilClass for bad accept headersStephen Becker IV2013-06-191-1/+1
|
* Remove Mime::Type#verify_request? and Mime::Type.browser_generated_types ↵kennyj2013-06-021-16/+0
| | | | were deprecated.
* Return nil for Mime::NullType#refAndrew White2013-04-101-0/+4
|
* Reverts rendering behavior when format is unknownGrzegorz Świrski2013-04-101-1/+5
| | | | | | | | | If a request has unknown format (eg. /foo.bar), the renderer fallbacks to default format. This patch reverts Rails 3.2 behavior after c2267db commit. Fixes issue #9654.
* Mark unused variables and make some style fixesAgis Anastasopoulos2013-04-081-2/+2
| | | | It'd be a nice convention to mark the unused variables like this, now that Ruby 2 will issue no warnings for such vars being unused.
* return Mime::NullType if format is unknownAngelo Capilleri2012-12-221-1/+12
| | | | | | | | | | If a request has an unknown format, the methods html?, xml?, json? ...etc not raise an Exception. This patch add a class Mime::NullType, that is returned when request.format is unknown and it responds false to the methods that ends with '?' and true to 'nil?'. It refers to #7837, this issue is considered a improvement not a bug.
* implement to_a and to_ary so that the Array() call in template.rb willAaron Patterson2012-11-091-9/+14
| | | | | | | | | | | | | | | | not raise so many exceptions: https://github.com/rails/rails/blob/master/actionpack/lib/action_view/template.rb#L126 irb(main):001:0> class Foo; def method_missing(*args); super; end end => nil irb(main):002:0> $DEBUG = true => true irb(main):003:0> Array(Foo.new) Exception `NoMethodError' at (irb):1 - undefined method `to_ary' for #<Foo:0x007f854390e488> Exception `NoMethodError' at (irb):1 - undefined method `to_a' for #<Foo:0x007f854390e488> => [#<Foo:0x007f854390e488>] irb(main):004:0>
* 1.9 hash syntax changes to docsAvnerCohen2012-10-311-2/+2
|