From 029854f4c482cac97066ad78cf28eba9e52f007b Mon Sep 17 00:00:00 2001 From: Marsel Mustafin Date: Fri, 10 Jul 2020 18:48:03 +0300 Subject: [PATCH] Replace stale recipe for custom middleware ordering with description of current behaviour (#407) Replace stale recipe for custom middleware ordering while using Rack::Deflater with description of current behaviour --- README.md | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index aa516d65..0349ded6 100644 --- a/README.md +++ b/README.md @@ -361,32 +361,13 @@ html_container|`body`|The HTML container (as a jQuery selector) to inject the mi show_total_sql_count|`false`|Displays the total number of SQL executions. enable_advanced_debugging_tools|`false`|Enables sensitive debugging tools that can be used via the UI. In production we recommend keeping this disabled as memory and environment debugging tools can expose contents of memory that may contain passwords. -### Custom middleware ordering (required if using `Rack::Deflate` with Rails) - -If you are using `Rack::Deflate` with rails and rack-mini-profiler in its default configuration, -`Rack::MiniProfiler` will be injected (as always) at position 0 in the middleware stack. This -will result in it attempting to inject html into the already-compressed response body. To fix this, -the middleware ordering must be overriden. - -To do this, first add `, require: false` to the gemfile entry for rack-mini-profiler. -This will prevent the railtie from running. Then, customize the initialization -in the initializer like so: - -```ruby -require 'rack-mini-profiler' - -Rack::MiniProfilerRails.initialize!(Rails.application) - -Rails.application.middleware.delete(Rack::MiniProfiler) -Rails.application.middleware.insert_after(Rack::Deflater, Rack::MiniProfiler) -``` - -Deleting the middleware and then reinserting it is a bit inelegant, but -a sufficient and costless solution. It is possible that rack-mini-profiler might -support this scenario more directly if it is found that -there is significant need for this confriguration or that -the above recipe causes problems. +### Using MiniProfiler with `Rack::Deflate` middleware +If you are using `Rack::Deflate` with Rails and `rack-mini-profiler` in its default configuration, +`Rack::MiniProfiler` will be injected (as always) at position 0 in the middleware stack, +which means it will run after `Rack::Deflate` on response processing. To prevent attempting to inject +HTML in already compressed response body MiniProfiler will suppress compression by setting +`identity` encoding in `Accept-Encoding` request header. ## Special query strings