Created
April 26, 2009 00:39
-
-
Save mojombo/101822 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
# This is a config file for ProxyMachine. It pulls the username out of | |
# the Git stream and can proxy to different locations based on that value | |
# Run with `proxymachine -c examples/git.rb` | |
class GitRouter | |
# Look at the routing table and return the correct address for +name+ | |
# Returns "<host>:<port>" e.g. "ae8f31c.example.com:9418" | |
def self.lookup(name) | |
puts "Proxying for user #{name}" | |
"localhost:9418" | |
end | |
end | |
# Perform content-aware routing based on the stream data. Here, the | |
# header information from the Git protocol is parsed to find the | |
# username and a lookup routine is run on the name to find the correct | |
# backend server. If no match can be made yet, do nothing with the | |
# connection yet. | |
proxy do |data| | |
if data =~ %r{^....git-upload-pack /([\w\.\-]+)/[\w\.\-]+\000host=(.+)\000} | |
name, host = $1, $2 | |
GitRouter.lookup(name) | |
else | |
:noop | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment