Skip to content

Instantly share code, notes, and snippets.

@choonkeat
Created February 15, 2009 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save choonkeat/64557 to your computer and use it in GitHub Desktop.
Save choonkeat/64557 to your computer and use it in GitHub Desktop.
a commonly needed server side component: expand tinyurl (et al)
class BigurlsController < ApplicationController
def index
url = URI.parse(params[:url])
res = Net::HTTP.start(url.host, url.port) {|http| http.get([url.path, url.query].compact.join('?'), "User-Agent" => request.user_agent) }
render :text => (res['location'] || params[:url])
rescue
"#{params[:url]}##{$!.to_s}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment