Created
August 21, 2015 14:45
-
-
Save bltavares/06991029f28f42582fce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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