-
-
Save gabamnml/6188342 to your computer and use it in GitHub Desktop.
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
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