| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
| |
|
|
|
|
| |
`ActionDispatch::Static#initialize`
|
|
|
|
|
| |
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The `ActionDispatch::Static` middleware is used low down in the stack to serve
static assets before doing much processing. Since it's called from so low in
the stack, we don't have access to the request ID at this point, and generally
won't have any exception handling defined (by default `ShowExceptions` is added
to the stack quite a bit higher and relies on logging and request ID).
Before https://github.com/rails/rails/commit/8f27d6036a2ddc3cb7a7ad98afa2666ec163c2c3
this middleware would ignore unknown HTTP methods, and an exception about these
would be raised higher in the stack. After that commit, however, that exception
will be raised here.
If we want to keep `ActionDispatch::Static` so low in the stack (I think we do)
we should suppress the `ActionController::UnknownHttpMethod` exception here,
and instead let it be raised higher up the stack, once we've had a chance to
define exception handling behaviour.
This PR updates `ActionDispatch::Static` so it passes `Rack::Request` objects to
`ActionDispatch::FileHandler`, which won't raise an
`ActionController::UnknownHttpMethod` error. If an unknown method is
passed, it should exception higher in the stack instead, once we've had a
chance to define exception handling behaviour.`
|
|
|
|
| |
This commit uses the new method in Rack to check if a path is valid.
|
|
|
|
|
|
|
|
| |
gzipped version exists or not. This is helpful for CDN's to later distinguish assets, based on previous, current copies and introduced gzip version if any."
This reverts commit 067c52f608568e35181830a5c1016e382650e655.
Conversation: https://github.com/rails/rails/pull/23120#issuecomment-173007011
|
|
|
|
|
|
|
|
| |
version exists or not. This is helpful for CDN's to later distinguish assets, based on previous, current copies and introduced gzip version if any.
For ref: https://www.fastly.com/blog/best-practices-for-using-the-vary-header
This change sets `Vary` header always, to be on safer side
|
|
|
|
|
|
| |
File paths cannot contain null byte characters and methods that do path
operations such as Rack::Utils#clean_path_info will raise unwanted
errors.
|
| |
|
|\
| |
| |
| | |
Add basic support for access control headers to ActionDispatch::Static
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Now ActionDispatch::Static can accept HTTP headers so that developers
will have control of returning arbitrary headers like
'Access-Control-Allow-Origin' when a response is delivered. They can
be configured through `#config.public_file_server.headers`:
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=60",
"Access-Control-Allow-Origin" => "http://rubyonrails.org"
}
Also deprecate `config.static_cache_control` in favor of
`config.public_file_server.headers`.
|
| |
| |
| |
| |
| |
| | |
Escaping and unescaping paths is different than query parameters, and we
need to respect that. This commit uses the new method in Rack to escape
and unescape paths. Fixes #11816
|
| |
| |
| |
| |
| |
| |
| | |
Implement `serve` on the middleware. Nothing can be placed between the
instance of FileHandler and Static because Static instantiates an
instance of FileHandler. IOW there is no reason to implement the `call`
API in this case.
|
| | |
|
|/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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)
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
and use coherent quoting/spacing.
This should hopefully fix a regression that was introduced with #20017,
causing deployment pushes to Heroku to be rejected with the following
trace:
ArgumentError: wrong number of arguments (2 for 3)
remote:
/tmp/build_a3b8845b716508af12d99859d1a58c5c/vendor/bundle/ruby/2.2.0/bun
dler/gems/rails-0ef7e73f0af7/actionpack/lib/action_dispatch/middleware/s
tatic.rb:16:in `initialize'
remote:
/tmp/build_a3b8845b716508af12d99859d1a58c5c/vendor/bundle/ruby/2.2.0/gem
s/heroku-deflater-0.5.3/lib/heroku-deflater/serve_zipped_assets.rb:15:in
`new'
remote:
/tmp/build_a3b8845b716508af12d99859d1a58c5c/vendor/bundle/ruby/2.2.0/gem
s/heroku-deflater-0.5.3/lib/heroku-deflater/serve_zipped_assets.rb:15:in
`initialize'
remote:
/tmp/build_a3b8845b716508af12d99859d1a58c5c/vendor/bundle/ruby/2.2.0/bun
dler/gems/rails-0ef7e73f0af7/actionpack/lib/action_dispatch/middleware/s
tack.rb:43:in `new'
remote:
/tmp/build_a3b8845b716508af12d99859d1a58c5c/vendor/bundle/ruby/2.2.0/bun
dler/gems/rails-0ef7e73f0af7/actionpack/lib/action_dispatch/middleware/s
tack.rb:43:in `build'
remote:
/tmp/build_a3b8845b716508af12d99859d1a58c5c/vendor/bundle/ruby/2.2.0/bun
dler/gems/rails-0ef7e73f0af7/actionpack/lib/action_dispatch/middleware/s
tack.rb:118:in `block in build'
remote:
/tmp/build_a3b8845b716508af12d99859d1a58c5c/vendor/bundle/ruby/2.2.0/bun
dler/gems/rails-0ef7e73f0af7/actionpack/lib/action_dispatch/middleware/s
tack.rb:118:in `each'
remote:
/tmp/build_a3b8845b716508af12d99859d1a58c5c/vendor/bundle/ruby/2.2.0/bun
dler/gems/rails-0ef7e73f0af7/actionpack/lib/action_dispatch/middleware/s
tack.rb:118:in `inject'
remote:
/tmp/build_a3b8845b716508af12d99859d1a58c5c/vendor/bundle/ruby/2.2.0/bun
dler/gems/rails-0ef7e73f0af7/actionpack/lib/action_dispatch/middleware/s
tack.rb:118:in `build'
remote:
/tmp/build_a3b8845b716508af12d99859d1a58c5c/vendor/bundle/ruby/2.2.0/bun
dler/gems/rails-0ef7e73f0af7/railties/lib/rails/engine.rb:509:in `app'
remote:
/tmp/build_a3b8845b716508af12d99859d1a58c5c/vendor/bundle/ruby/2.2.0/bun
dler/gems/rails-0ef7e73f0af7/railties/lib/rails/application/finisher.rb:
34:in `block in <module:Finisher>'
remote:
/tmp/build_a3b8845b716508af12d99859d1a58c5c/vendor/bundle/ruby/2.2.0/bun
dler/gems/rails-0ef7e73f0af7/railties/lib/rails/initializable.rb:30:in
`instance_exec'
remote:
/tmp/build_a3b8845b716508af12d99859d1a58c5c/vendor/bundle/ruby/2.2.0/bun
dler/gems/rails-0ef7e73f0af7/railties/lib/rails/initializable.rb:30:in
`run'
remote:
/tmp/build_a3b8845b716508af12d99859d1a58c5c/vendor/bundle/ruby/2.2.0/bun
dler/gems/rails-0ef7e73f0af7/railties/lib/rails/initializable.rb:55:in
`block in run_initializers'
remote:
/tmp/build_a3b8845b716508af12d99859d1a58c5c/vendor/bundle/ruby/2.2.0/bun
dler/gems/rails-0ef7e73f0af7/railties/lib/rails/initializable.rb:54:in
`run_initializers'
remote:
/tmp/build_a3b8845b716508af12d99859d1a58c5c/vendor/bundle/ruby/2.2.0/bun
dler/gems/rails-0ef7e73f0af7/railties/lib/rails/application.rb:352:in
`initialize!'
remote:
/tmp/build_a3b8845b716508af12d99859d1a58c5c/config/environment.rb:5:in
`<top (required)>'
|
|
|
|
|
|
| |
Set `config.static_index` to serve a static directory index file not
named `index`. For example, to serve `main.html` instead of `index.html`
for directory requests, set `config.static_index` to `"main"`.
|
|
|
|
|
|
| |
* Fix a few typos
* Wrap lines to 80 chars
* Use `+` instead of `<tt>`
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Windows
* https://github.com/rails/rails/issues/19187
* https://github.com/rails/rails/pull/19533
* https://github.com/macournoyer/thin/issues/268
These are serious Rails 4 regression for Redmine Bitnami Windows users.
https://community.bitnami.com/t/problems-with-3-0-1-installation-see-report-inside/30195/
It is not caused on webrick users.
Related:
* https://github.com/rack/rack/issues/732#issuecomment-67677272
* https://github.com/phusion/passenger/issues/1328
|
| |
|
|
|
|
|
| |
Rack::Lint raises an error saying "Content-Type header found in 304
response, not allowed".
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
It's unnecessary to call `#clean_path_info`. It doesn't need to be
called on the path with each extension. This reduces allocations to
`Rack::Utils` in integration tests.
Before `#clean_path_info` from `Rack::Utils` (line 622) was number 2
in top 5 allocations:
```
[["rack/lib/rack/utils.rb", 499, :T_STRING], [51034, 4539, 71559, 0, 12, 1791120]]
[["rack/lib/rack/utils.rb", 662, :T_STRING], [33012, 0, 27930, 0, 1, 1226009]]
[["rails/activesupport/lib/active_support/notifications/fanout.rb", 55, :T_DATA], [29998, 0, 25380, 0, 1, 3230600]]
[["rails/activesupport/lib/active_support/subscriber.rb", 99, :T_STRING], [29996, 0, 25378, 0, 2, 1113840]]
[["rails/activesupport/lib/active_support/notifications/instrumenter.rb", 52, :T_HASH], [29994, 147, 27014, 0, 11, 4897784]]
```
After `#clean_path_info` from `Rack::Utils` (line 622) does not appear
in the top 5 highest allocations:
```
[["rack/lib/rack/utils.rb", 499, :T_STRING], [47617, 2414, 68969, 0, 12, 1667360]]
[["rack/lib/rack/body_proxy.rb", 34, :T_ARRAY], [28230, 0, 26060, 0, 1, 1046800]]
[["rails/activesupport/lib/active_support/notifications/fanout.rb", 55, :T_DATA], [28208, 0, 26042, 0, 1, 3034096]]
[["rails/activesupport/lib/active_support/subscriber.rb", 99, :T_STRING], [28204, 0, 26040, 0, 1, 1046080]]
[["rails/activesupport/lib/active_support/callbacks.rb", 165, :T_DATA], [28200, 0, 26046, 0, 2, 3451800]]
```
|
|
|
|
|
| |
FileHandler#matches? should return false for files that are outside the
"root" path.
|
|
|
|
|
|
|
|
| |
Dir.glob can be a security concern. The original use was to provide logic of fallback files. Example a request to `/` should render the file from `/public/index.html`. We can replace the dir glob with the specific logic it represents. The glob {,index,index.html} will look for the current path, then in the directory of the path with index file and then in the directory of the path with index.html. This PR replaces the glob logic by manually checking each potential match. Best case scenario this results in one less file API request, worst case, this has one more file API request.
Related to #16464
Update: added a test for when a file of a given name (`public/bar.html` and a directory `public/bar` both exist in the same root directory. Changed logic to accommodate this scenario.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
- don't mutate PATH_INFO in env, test
- test fallback content type matches Rack::File
- change assertion style
- make HTTP_ACCEPT_ENCODING comparison case insensitive
- return gzip path from method instead of true/false so we don't have to assume later
- don't allocate un-needed hash.
Original comments:
https://github.com/rails/rails/commit/
cfaaacd9763642e91761de54c90669a88d772e5a#commitcomment-7468728
cc @jeremy
|
|
|
|
|
|
| |
If someone is using ActionDispatch::Static to serve assets and makes it past the `match?` then the file exists on disk and it will be served. This PR adds in logic that checks to see if the file being served is already compressed (via gzip) and on disk, if it is it will be served as long as the client can handle gzip encoding. If not, then a non gzip file will be served.
This additional logic slows down an individual asset request but should speed up the consumer experience as compressed files are served and production applications should be delivered with a CDN. This PR allows a CDN to cache a gzip file by setting the `Vary` header appropriately. In net this should speed up a production application that are using Rails as an origin for a CDN. Non-asset request speed is not affected in this PR.
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
In #5337 we forced the path encoding to ASCII-8BIT to prevent static
file handling from blowing up before an application has had chance to
deal with possibly invalid urls. However this has a negative side
effect of making it an incompatible encoding if the application's
public path has UTF-8 characters in it.
To work around the problem we check to see if the path has a valid
encoding once it has been unescaped. If it is not valid then we can
return early since it will not match any file anyway.
Fixes #13518
|
|
|
|
| |
See https://github.com/rails/rails/pull/8812#commitcomment-2416514
|
|
|
|
|
|
|
|
|
|
|
|
| |
See http://intertwingly.net/projects/AWDwR4/checkdepot/section-6.1.html
rake test produces:
"Rack::File headers parameter replaces cache_control after Rack 1.5."
Despite what the message says, it appears that the hearders parameter change
will be effective as of Rack 1.5:
https://github.com/rack/rack/blob/rack-1.4/lib/rack/file.rb#L24
https://github.com/rack/rack/blob/master/lib/rack/file.rb#L24
|
|
|
|
| |
This reverts commit c59734f756b79c39486c45273d2cc5d42cd0c864.
|
|
|
|
|
|
|
|
|
|
| |
This commit inverts the precedence in ActionDispatch::Static so that
dynamic content will be served before static content. This is so that
precompiled assets do not inadvertently get included when running in
development mode - it should have no effect in production where static
files are usually handled by the web server.
Closes #6421
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
RFC 3986[1] allows sub-delim characters in path segments unencoded,
however Rack::File requires them to be encoded so we use URI's
unescape method to leave them alone and then escape them again.
Also since the path gets passed to Dir[] we need to escape any glob
characters in the path.
[1]: http://www.ietf.org/rfc/rfc3986.txt
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
|
| |
This reverts commit 2dbb73bdda3b81947fd112486ac4285fb1a6e3a9.
Conflicts:
actionpack/lib/action_dispatch/middleware/static.rb
|
| |
|
| |
|
| |
|
|
|
|
| |
everyone calls super as expected.
|