Skip to content

Commit

Permalink
Replace stale recipe for custom middleware ordering with description …
Browse files Browse the repository at this point in the history
…of current behaviour (#407)

Replace stale recipe for custom middleware ordering
while using Rack::Deflater with description of current behaviour
  • Loading branch information
marselmustafin committed Jul 10, 2020
1 parent c8b19a4 commit 029854f
Showing 1 changed file with 6 additions and 25 deletions.
31 changes: 6 additions & 25 deletions README.md
Expand Up @@ -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

Expand Down

0 comments on commit 029854f

Please sign in to comment.