aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/http
Commit message (Collapse)AuthorAgeFilesLines
* Simplify codeMarcin Olichwirowicz2015-08-131-5/+4
| | | | | Since we are always responding with an array and using `any?`, we don't need to check if an array is empty
* Avoid unnecessary MatchData objectsMarcin Olichwirowicz2015-08-131-1/+1
|
* deprecate the env method on controller instancesAaron Patterson2015-08-071-1/+1
| | | | | | people should be accessing request information through the request object, not via the env hash. If they really really want at the env hash, then they can get it off the request.
* stop using @_env in the controller instanceAaron Patterson2015-08-071-0/+8
| | | | | | | Actions are processed through `dispatch`, so they should have the request set on them before any user land code can be executed. Lets stop setting _env on the controller, and give access to it through the `env` method.
* refactor param parsing middleware to use request objectsAaron Patterson2015-08-071-0/+8
| | | | | this is another place that we should stop directly accessing the env hash and let the request object take care of that for us
* Fix documentation on ActionDispatch::RequestGabriel Sobrinho2015-08-061-1/+1
|
* use a request object to access info from env in GetIpAaron Patterson2015-08-061-1/+7
| | | | | | | again, we want to hide the contents of `env` from the implementation. Allocate a request object to access the contents of env, but save allocations due to string literal allocations when accessing the env hash.
* ask the request if we should show exceptionsAaron Patterson2015-08-061-0/+7
| | | | | hide the env key in the request object so that other code doesn't need to know.
* prevent string allocationsAaron Patterson2015-08-061-1/+1
|
* get the underlying REQUEST_METHOD from the superclassAaron Patterson2015-08-061-1/+1
|
* Merge pull request #21131 from eagletmt/percent-filenameRafael Mendonça França2015-08-061-1/+7
|\ | | | | Fix Encoding::UndefinedConversionError with multibyte UTF-8 filename containing "%" character
| * Assume uploaded filename is UTF-8Kohei Suzuki2015-08-051-1/+7
| |
* | routes in the env via the request objectAaron Patterson2015-08-051-0/+4
| |
* | allocate a request object to avoid hash allocationsAaron Patterson2015-08-051-0/+4
|/ | | | | This decouples the `call` method from knowing the SCRIPT_NAME key and offloads decisions about how to access script_name
* Tiny documentation edits [ci skip]Robin Dupret2015-07-281-1/+1
|
* Merge pull request #20590 from vngrs/set_default_charsetRafael Mendonça França2015-07-271-6/+6
|\ | | | | Document, refactor and create test case for ActionDispatch::Response
| * Document, refactor and create test case for ↵Mehmet Emin İNAÇ2015-06-171-6/+6
| | | | | | | | ActionDispatch::Response#charset= method
* | rm `deep_munge`. You will live on in our hearts (and git history)Aaron Patterson2015-07-211-7/+2
| | | | | | | | | | Now that we have encoding strategies, we can just walk the params hash once to encode as HWIA, and remove nils.
* | push param encoding in to the utils moduleAaron Patterson2015-07-211-14/+1
| | | | | | | | we'll refactor deep munge mostly out of existence shortly
* | recurse for arrays in `normalize_encode_params`Aaron Patterson2015-07-211-5/+3
| | | | | | | | | | this just pushes the conditional in to the case / when so we can switch to method dispatch later
* | Freeze string literals when not mutated.schneems2015-07-192-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I wrote a utility that helps find areas where you could optimize your program using a frozen string instead of a string literal, it's called [let_it_go](https://github.com/schneems/let_it_go). After going through the output and adding `.freeze` I was able to eliminate the creation of 1,114 string objects on EVERY request to [codetriage](codetriage.com). How does this impact execution? To look at memory: ```ruby require 'get_process_mem' mem = GetProcessMem.new GC.start GC.disable 1_114.times { " " } before = mem.mb after = mem.mb GC.enable puts "Diff: #{after - before} mb" ``` Creating 1,114 string objects results in `Diff: 0.03125 mb` of RAM allocated on every request. Or 1mb every 32 requests. To look at raw speed: ```ruby require 'benchmark/ips' number_of_objects_reduced = 1_114 Benchmark.ips do |x| x.report("freeze") { number_of_objects_reduced.times { " ".freeze } } x.report("no-freeze") { number_of_objects_reduced.times { " " } } end ``` We get the results ``` Calculating ------------------------------------- freeze 1.428k i/100ms no-freeze 609.000 i/100ms ------------------------------------------------- freeze 14.363k (± 8.5%) i/s - 71.400k no-freeze 6.084k (± 8.1%) i/s - 30.450k ``` Now we can do some maths: ```ruby ips = 6_226k # iterations / 1 second call_time_before = 1.0 / ips # seconds per iteration ips = 15_254 # iterations / 1 second call_time_after = 1.0 / ips # seconds per iteration diff = call_time_before - call_time_after number_of_objects_reduced * diff * 100 # => 0.4530373333993266 miliseconds saved per request ``` So we're shaving off 1 second of execution time for every 220 requests. Is this going to be an insane speed boost to any Rails app: nope. Should we merge it: yep. p.s. If you know of a method call that doesn't modify a string input such as [String#gsub](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37) please [give me a pull request to the appropriate file](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37), or open an issue in LetItGo so we can track and freeze more strings. Keep those strings Frozen ![](https://www.dropbox.com/s/z4dj9fdsv213r4v/let-it-go.gif?dl=1)
* | 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`.
* | move buffer caching on to the bufferAaron Patterson2015-07-131-3/+11
| |
* | added description instead of remove usage [ci skip]Julio Lopez2015-07-111-1/+1
| |
* | Allow filtering params based on parent keysGuillaume Malette2015-06-221-7/+17
| | | | | | | | | | | | | | | | | | | | Add the possibility to only filter parameters based on their full path instead of relying on the immediate key. config.filter_parameters += ['credit_card.code'] { 'credit_card' => { 'code' => '[FILTERED]' }, 'source' => { 'code' => '<%= puts 5 %>' } }
* | Fix the comment about attr_reader of headers [ci skip]Mehmet Emin İNAÇ2015-06-161-1/+1
|/
* remove `header=` on the response object.Aaron Patterson2015-06-152-13/+14
| | | | | | People should be free to mutate the header object, but not to set a new header object. That header object may be specific to the webserver, and we need to hide it's internals.
* set the default charset in response initializeAaron Patterson2015-06-151-4/+12
| | | | | this way we don't have to mutate the instance (as much) when writing a rack response
* A few documentation tweaks [ci skip]Robin Dupret2015-06-071-2/+2
| | | | [Robin Dupret & Shunsuke Aida]
* Remove already defined methods in super class of ActionDispatch::Request classMehmet Emin İNAÇ2015-05-281-36/+0
| | | | | | | These methods had defined in 2004 by dhh in initial commit and `ActionDispatch::Request` class has been inherited from `Rack::Request` class in 2009 by josh. In 2014 these methods and more of them defined in `Rack::Request` class so we don't need them anymore in rails codebase.
* Merge pull request #20329 from EduardoBautista/json-api-supportRafael Mendonça França2015-05-271-1/+1
|\ | | | | Add application/vnd.api+json alias to the JSON MIME Type.
| * Add application/vnd.api+json alias to the JSON MIME Type.Eduardo Bautista2015-05-271-1/+1
| |
* | Documentation for ActionDispatch::Request form_data? method [ci skip]Mehmet Emin İNAÇ2015-05-271-0/+2
| |
* | Add missing nodocs and docs for ActionDispatch::Request [ci skip]Mehmet Emin İNAÇ2015-05-261-3/+5
| | | | | | | | add missing dot to end of the doc
* | Use memoization while accessing request headers for minimizing memory usageMehmet Emin İNAÇ2015-05-251-1/+1
|/
* remove useless ivarAaron Patterson2015-05-231-1/+0
| | | | I should have deleted this earlier with 42e66fac38b54dd53d062fb5d3376218ed2ffdae
* move request id manipulation to the request objectAaron Patterson2015-05-221-1/+13
| | | | this way we can keep the knowledge of `env` hash keys in one place.
* Spelling/typo/grammatical fixes [ci skip]karanarora2015-05-231-1/+1
| | | | | | | | | | spelling fix [ci skip] example to be consistent [ci skip] grammatical fix typo fixes [ci skip]
* Use ruby 1.9 lambda syntax in documentations [ci skip]Mehmet Emin İNAÇ2015-05-031-1/+1
|
* Fix method signature of `parse_query` to match rackeileencodes2015-04-061-1/+1
| | | | | | | Recently rack was changed to have a second argument on the `parse_query` method (in rack/rack#781). Rails relies on this and it's `parse_query` method was complaining about missing the second argument. I changed the arguments to `*` so we don't have this issue in the future.
* Add ActiveSupport::ArrayInquirer and Array#inquiryGeorge Claghorn2015-03-241-27/+2
| | | | | | | | | | | | | | | | | | | | | | Wrapping an array in an `ArrayInquirer` gives a friendlier way to check its string-like contents. For example, `request.variant` returns an `ArrayInquirer` object. To check a request's variants, you can call: request.variant.phone? request.variant.any?(:phone, :tablet) ...instead of: request.variant.include?(:phone) request.variant.any? { |v| v.in?([:phone, :tablet]) } `Array#inquiry` is a shortcut for wrapping the receiving array in an `ArrayInquirer`: pets = [:cat, :dog] pets.cat? # => true pets.ferret? # => false pets.any?(:cat, :ferret} # => true
* Provide friendlier access to request variantsGeorge Claghorn2015-03-241-7/+34
| | | | Closes #18933.
* Fix handling of empty X_FORWARDED_HOST header.adam2015-03-201-1/+1
| | | | | | Previously, an empty X_FORWARDED_HOST header would cause Actiondispatch::Http:URL.raw_host_with_port to return nil, causing Actiondispatch::Http:URL.host to raise a NoMethodError.
* Merge pull request #19215 from ↵Sean Griffin2015-03-051-3/+1
|\ | | | | | | | | gsamokovarov/revert-ruby-2-2-0-kwarg-crash-workarounds Revert work arounds for upstream Ruby 2.2.0 kwargs bug
| * Revert work arounds for upstream Ruby 2.2.0 kwargs bugGenadi Samokovarov2015-03-051-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The bug caused a segfault and you can find more info about it at: https://bugs.ruby-lang.org/issues/10685. We did a couple of work arounds, but 2.2.1 rolled out and those aren't needed anymore. Here are the reverted commits: - Revert "Work around for upstream Ruby bug #10685", commit 707a433870e9e06af688f85a4aedc64a90791a64. - Revert "Fix segmentation fault in ActionPack tests", commit 22e0a22d5f98e162290d9820891d8191e720ad3b. I'm also bumping the Ruby version check to 2.2.1 to prevent future segfaults.
* | nodoc filtered_location [ci skip]Sushruth Sivaramakrishnan2015-03-051-1/+1
|/
* Merge pull request #19147 from gsamokovarov/work-around-ruby-10695Eileen M. Uchitelle2015-03-021-1/+3
|\ | | | | Work around for upstream Ruby bug #10685
| * Work around for upstream Ruby bug #10685Genadi Samokovarov2015-03-011-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In f6e293ec54f02f83cdb37502bea117f66f87bcae we avoided a segfault in the tests, however I think we should try to avoid the crash, as it may happen in user code as well. Here is what I distiled the bug down to: ```ruby # Rails case - works on 2.0, 2.1; crashes on 2.2 require 'action_dispatch' ActionDispatch::Response.new(200, "Content-Type" => "text/xml") # General case - works on 2.0, 2.1; crashes on 2.2 def foo(optional = {}, default_argument: nil) end foo('quux' => 'bar') ```
* | ask the routes objects for its Rack env keyAaron Patterson2015-03-021-1/+1
| | | | | | | | | | | | this centralizes the logic for determining the script name key and drops object allocations when calling `engine_script_name` (which is called on each `url_for`).
* | drop string allocations per model url_for call in viewsAaron Patterson2015-03-011-1/+1
|/ | | | | | | | | | | | ```ruby article = Article.new.tap(&:save!) view.url_for article result = ObjectSpace::AllocationTracer.trace do 3000.times { view.url_for article } end p ObjectSpace::AllocationTracer.allocated_count_table[:T_STRING] / 3000 ```