Skip to content

Instantly share code, notes, and snippets.

@jacarandang
Created July 15, 2015 05:38
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 jacarandang/d6ed7f79840e5f238325 to your computer and use it in GitHub Desktop.
Save jacarandang/d6ed7f79840e5f238325 to your computer and use it in GitHub Desktop.
Rewrite.rb for squid3
#!/usr/bin/env ruby
# url rewriter for rubygems squid proxy
STDOUT.sync = true
while line = gets
url = line.split(' ')[0]
# Cargo-culted this conditional, not sure if it is necessary
response = if url
# Need to find a better way to cache this redirect, rather than hard-coding
# it.
if url.include?("http://rubygems.org/gems/")
"302:" + url.gsub(
"http://rubygems.org/",
"http://production.cf.rubygems.org/"
)
else
""
end
else
""
end
puts response
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment