Skip to content

Instantly share code, notes, and snippets.

@ivyl
Created July 28, 2011 11:09
Show Gist options
  • Save ivyl/1111388 to your computer and use it in GitHub Desktop.
Save ivyl/1111388 to your computer and use it in GitHub Desktop.
Errornomous Response Generator

Error Generator

HowTo Use?

./error-generator 8080

go to localhost:8080/PATH

PATHS

/error/CODE

generates response with CODE

/slow/SECONDS

generates response after given time

/random

randomly returns 200 and 500

#!/usr/bin/env ruby
require 'rubygems'
require 'rack'
class ErrorGenerator
def call(env)
path = File.split(env["REQUEST_PATH"])
if path.first == '/error'
response = path[1] || 404
elsif path.first == '/slow'
response = 200
sleep(path[1].to_i)
elsif path[1] == 'random'
response = rand(2) == 1 ? 200 : 500
else
response = 404
end
[response.to_i, {'Content-Type' => 'text/html'}, "Error #{response} Generated"]
end
end
Rack::Handler::WEBrick.run(
ErrorGenerator.new,
:Port => ARGV[0]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment