Sha256: 19d4855cc284901788b19300d18431477fb4fc4084c122317ead2fe926a31808

Contents?: true

Size: 566 Bytes

Versions: 1

Compression:

Stored size: 566 Bytes

Contents

module Rack
  class ForceStatus
    def initialize(app, options={})
      @app = app
      @param = options[:param] || 'force_status'
      @header = options[:header] || 'X-Original-Status-Code'
    end
    
    def call(env)
      request = Rack::Request.new(env)
      force_status = request.params.delete(@param).to_i
      
      status, headers, body = @app.call(env)
      
      if force_status > 0 && status != force_status
        headers[@header] = status.to_s
        status = force_status
      end
      
      [status, headers, body]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-force-status-0.0.1 lib/rack/force-status/middleware.rb