Skip to content

Instantly share code, notes, and snippets.

@rsutphin
Created July 6, 2011 16:27
Show Gist options
  • Select an option

  • Save rsutphin/1067669 to your computer and use it in GitHub Desktop.

Select an option

Save rsutphin/1067669 to your computer and use it in GitHub Desktop.
Sinatra app that emits various kinds of 3xx redirects
require 'sinatra'
get '/' do
<<-HTML
<ul>
<li><a href="/301.html">301</a></li>
<li><a href="/302.html">302</a></li>
<li><a href="/303.html">303</a></li>
</ul>
HTML
end
get %r{/(30\d)\.html} do |code|
[
code.to_i,
{ 'Location' => "/#{code}-result.html" },
"Redirecting as #{code}"
]
end
get %r{/(30\d)-result\.html} do |code|
"You got here from a #{code}!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment