No commit activity in last 3 years
No release in over 3 years
A Rack middleware gem that overrides responses for web applications
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies
 Project Readme

rack-override-path

Rack::OverridePath overrides responses for web applications

Installation

Install the gem:

gem install rack-override-path

Or in your Gemfile:

gem 'rack-override-path'

How to use

Example webserver setup using webrick

require 'rack/override-path'
require 'webrick'

app = lambda do |_env|
[200, { 'Content-Type' => 'text/plain' }, ['Hello World']]
end

Rack::Handler::WEBrick.run Rack::OverridePath.new(app)

Configure Override Response

Specify a path, with one or more Override Parameters.

Subsequent requests matching path will be overridden.

Example

POST /override/path
{
  "delay": 2,
  "headers": { "Content-Type": "text/plain" },
  "status": 404,
  "body": "Nothing found",
  "method": "GET",
  "path": "/index.html"
}

In the example above, GET requests for /index.html will respond with a 404 status with Nothing found in the body after a 2 second delay

The path can be literal (e.g /index.html) or a regular expression (e.g .*videos.*)

Available Override Parameters

At least one Override Parameter must be included in each Configured Override

  • body
  • delay - should be an Integer value, in seconds
  • headers
  • status - should be an Integer value

Available Filters

Filters are optional

  • method - acceptable values are GET,PUT, POST, PATCH, DELETE, HEAD, OPTIONS. If method parameter is not specified, all methods for the matching path are overridden

List Overridden Responses

Example

GET /override/path
[
    {
        "delay": 2,
        "headers": {
            "Content-Type": "text/plain"
        },
        "status": 404,
        "body": "Nothing found",
        "method": "GET",
        "path": "/index.html"
    }
]

Delete all Overridden Responses

Example

DELETE /override/path
[]