Created
October 14, 2009 21:05
-
-
Save whoisjake/210408 to your computer and use it in GitHub Desktop.
My first entry for coderack.org
This file contains 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
module Rack | |
# A rack middleware for wrapping sites in http://kanyelicious.appspot.com/. | |
class Kanye | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
request_uri = env['REQUEST_URI'] | |
# Check if kanye=true exists, remove param, and stop | |
if (/kanye=true/ =~ request_uri) | |
env['REQUEST_URI'].gsub!("&kanye=true","") | |
@app.call(env) | |
else | |
request_uri += ((request_uri.include?("?")) ? "&" : "?") + "kanye=true" | |
full_request = "http://" + env['HTTP_HOST'] + request_uri | |
# Otherwise redirect | |
[302, {'Location' => "http://kanyelicious.appspot.com/" + full_request }, ['Redirecting...']] | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment