Skip to content

Instantly share code, notes, and snippets.

@gabamnml
Forked from petewarden/tumblrproxy.rb
Last active December 20, 2015 20:09
Show Gist options
  • Save gabamnml/6188342 to your computer and use it in GitHub Desktop.
Save gabamnml/6188342 to your computer and use it in GitHub Desktop.
get '/blog*' do
begin
path = params[:splat][0]
source_url = URI.parse('http://asdf.tumblr.com' + path.gsub(/ /, '+'))
source_content_type = ''
source_body = open(source_url) do |f|
source_content_type = f.content_type
f.read
end
if source_content_type == 'text/html'
output_base = request.base_url + '/blog'
output_body = source_body.gsub(/\b(href|src|rel)="\/\//, '\1="https:\/\/')
output_body = output_body.gsub(/\b(href|src|rel)="\//, '\1="' + output_base + '/')
output_body = output_body.gsub(/\b(href|src|rel)="http:\/\/asdf\.tumblr\.com/, '\1="/blog')
else
output_body = source_body
end
content_type source_content_type
output_body
rescue OpenURI::HTTPError
erb :error
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment