Skip to content

Instantly share code, notes, and snippets.

@bltavares
Created August 21, 2015 14:45
Show Gist options
  • Save bltavares/06991029f28f42582fce to your computer and use it in GitHub Desktop.
Save bltavares/06991029f28f42582fce to your computer and use it in GitHub Desktop.
require 'rack'
app = Proc.new do |env|
if env['PATH_INFO'] == '/301'
next ['301', {'Content-Type' => 'text/html', 'X-Auth-Token' => 'This-Should-Be-Forwarded', 'Location' => '/headers'}, []]
end
if env['PATH_INFO'] == '/302'
next ['302', {'Content-Type' => 'text/html', 'X-Auth-Token' => 'This-Should-Be-Forwarded', 'Location' => '/headers'}, []]
end
if env['PATH_INFO'] == '/headers'
headers = env.select {|k,v| k.start_with? 'HTTP_'}
.collect {|pair| [pair[0].sub(/^HTTP_/, ''), pair[1]]}
.collect {|pair| pair.join(": ") << "<br>"}
next ['200', {'Content-Type' => 'text/html'}, headers]
end
body = """
<form method=post action='/301'>
<input type=submit value=301>
</form>
<form method=post action='/302'>
<input type=submit value=302>
</form>
"""
['200', {'Content-Type' => 'text/html'}, [body]]
end
Rack::Handler::WEBrick.run app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment