class Rack::AddressMunging

The Rack::AddressMunging middleware, meant to be used in your Rack stack.

All other modules meant for use in your application are autoloaded here, so it should be enough just to require 'rack/address_munging' in your code.

To add the middleware to your stack, use: use Rack::AddressMunging

If you want to use another munging strategy, precise it as an argument: use Rack::AddressMunging, strategy: :hex

Constants

VERSION

Attributes

strategy[R]

Public Class Methods

new(app, options = {}) click to toggle source
# File lib/rack/address_munging.rb, line 22
def initialize(app, options = {})
  @app = app
  @options = { strategy: :Hex }.merge(options)
  @strategy = Strategy.const_get(@options[:strategy]).new
end

Public Instance Methods

call(env) click to toggle source
# File lib/rack/address_munging.rb, line 28
def call(env)
  @status, @headers, @response = @app.call(env)
  mung! if html?
  [@status, @headers, @response]
end

Private Instance Methods

html?() click to toggle source
# File lib/rack/address_munging.rb, line 36
def html?
  !(@headers['Content-Type'] =~ /html/).nil?
end
mung!() click to toggle source
# File lib/rack/address_munging.rb, line 40
def mung!
  @response = Response.new([], @status, @headers).tap do |r|
    @strategy.apply(r, @response)
  end
end