Browse files

Add HTML response body with link to the new URL.

  • Loading branch information...
1 parent 5052e30 commit de31b5ecd96ee87f8fafd65652744082d29de6bb @tylerhunt committed Mar 6, 2012
Showing with 16 additions and 1 deletion.
  1. +16 −1 lib/rack-canonical-host.rb
View
17 lib/rack-canonical-host.rb
@@ -1,5 +1,16 @@
module Rack # :nodoc:
class CanonicalHost
+ HTML_TEMPLATE = <<-HTML
+ <!DOCTYPE html>
+ <html lang="en-US">
+ <head><title>301 Moved Permanently</title></head>
+ <body>
+ <h1>Moved Permanently</h1>
+ <p>The document has moved <a href="%s">here</a>.</p>
+ </body>
+ </html>
+ HTML
+
def initialize(app, host=nil, &block)
@app = app
@host = host
@@ -8,7 +19,11 @@ def initialize(app, host=nil, &block)
def call(env)
if url = url(env)
- [301, { 'Location' => url, 'Content-Type' => 'text/html' }, ['Redirecting...']]
+ [
+ 301,
+ { 'Location' => url, 'Content-Type' => 'text/html' },
+ [HTML_TEMPLATE % url]
+ ]
else
@app.call(env)
end

5 comments on commit de31b5e

@nbibler

👍

@tylerhunt
Owner

Better? Did you happen to test it?

@nbibler

I was just noticing that there were no specs on the library. I haven't tested it yet. But, glancing at it, it looks like it should work. ;)

@nbibler

I'd be happy to add some specs to the library if you don't have time for it, btw.

@tylerhunt
Owner

It's not a big priority for me right now, so if you feeling like putting together a pull request for some specs, I'd definitely be game.

Please sign in to comment.