Skip to content

Instantly share code, notes, and snippets.

@mojombo
Created April 26, 2009 00:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mojombo/101822 to your computer and use it in GitHub Desktop.
Save mojombo/101822 to your computer and use it in GitHub Desktop.
# 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