No commit activity in last 3 years
No release in over 3 years
Rack middleware for forcing status codes on responses.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

>= 0
 Project Readme

Rack::ForceStatus Build Status

Rack::ForceStatus is a simple Rack middleware for forcing status codes on responses. This is useful for dealing with things like XDomainRequest's inability to provide responseText on errors. We can now return the error with a 200 response that XDomainRequest can receive and handle.

Installation

Install the Rack::ForceStatus gem with a simple:

gem install rack-force-status

Or add it to your Gemfile:

gem 'rack-force-status'

Usage

Use the Rack::ForceStatus middleware like anything else:

use Rack::ForceStatus

Or for Rails application, add the following line to your application config file (config/application.rb for Rails 3 & 4, config/environment.rb for Rails 2):

config.middleware.use Rack::ForceStatus

From there you can force the status on any request by passing a force_status param, set to the value of the status you'd like. For example, if you'd like everything to always return successful, you'd do:

http://myapp.com/some/path?force_status=200

In addition to forcing the status to whatever you've specified, if the original status was different you will get a header added telling you what it was originally.

X-Original-Status-Code: 422

Options

If you'd like to customize the incoming param name or the outgoing header name, you can pass them as options.

config.middleware.use Rack::ForceStatus, :param => 'my-custom-param', :header => 'My-Custom-Header'