Created
July 15, 2015 05:38
-
-
Save jacarandang/d6ed7f79840e5f238325 to your computer and use it in GitHub Desktop.
Rewrite.rb for squid3
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
#!/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