Skip to content
Rack Middleware: Find and replace on response
Ruby
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
test
.gitignore
Gemfile
Gemfile.lock
README.rdoc
Rakefile
rack_replace.gemspec

README.rdoc

Rack::Replace

Rack middleware which will perform a find/replace on the response body. This is basically a re-implementation of the following Rails code:

after_filter {|c| c.response.body.gsub 'foo', 'bar'}

The advantage of this module over the above code is:

  • It will work in any rack-compatible environment.

  • It is streaming friendly as it operates on each chunk given to rack.

Usage

use Rack::Replace, 'foo', 'bar'
use Rack::Replace 'HOST' {|env, match| env['HTTP_HOST']}

For more advanced uses see rack_image_size and rack_new_window.

Credit

This gem was developed by Eric Anderson (pixelwareinc.com).

Something went wrong with that request. Please try again.