module Rack class Embiggener def initialize(app) @app = app end def call(env) status, headers, body = @app.call(env) headers.delete('Content-Length') response = Rack::Response.new( Rack::Embiggener.embiggen_urls(body), status, headers ) response.finish return response.to_a end def self.embiggen_urls(original_body) 
 new_body = [] original_body.each { |line| tinys = line.scan(/(http:\/\/(?:www\.)?tinyurl\.com\/(.{6}))/) 
 new_body << tinys.uniq.inject(line) do |body, tiny| 
 original_tiny = tiny[0] 
 preview_url = "http://preview.tinyurl.com/#{tiny[1]}" 
 response = Net::HTTP.get_response(URI.parse(preview_url)) 
 embiggened_url = response.body.match(/redirecturl" href="(.*)">/)[1] 

 body.gsub(original_tiny, embiggened_url) 
 end 
 } 
 new_body 
 end end
 end