Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Pass whole base_url to proxy method.

  • Loading branch information...
commit ba0b8ccfe34dab86f3969fa62b84a6dbd42560cb 1 parent 603279e
@technomancy authored
Showing with 12 additions and 15 deletions.
  1. +11 −14 lib/sokoban.rb
  2. +1 −1  lib/sokoban/receiver.rb
View
25 lib/sokoban.rb
@@ -10,18 +10,16 @@ def initialize
@redis = Redis.new(:url => ENV["REDIS_URL"])
end
- def proxy(hostname, port=80, username=nil, password=nil)
+ def proxy(env, base_url)
req = Rack::Request.new(env)
- auth = [username, password].join(":")
- uri = "#{env["rack.url_scheme"]}://#{auth}@#{hostname}:#{port}"
- uri += env["PATH_INFO"]
- uri += "?" + env["QUERY_STRING"] unless env["QUERY_STRING"].empty?
+ url = base_url + env["PATH_INFO"]
+ url += "?" + env["QUERY_STRING"] unless env["QUERY_STRING"].empty?
begin # only want to catch proxy errors, not app errors
- proxy = Rack::StreamingProxy::ProxyRequest.new(req, uri)
+ proxy = Rack::StreamingProxy::ProxyRequest.new(req, url)
[proxy.status, proxy.headers, proxy]
rescue => e
- msg = "Proxy error when proxying to #{uri}: #{e.class}: #{e.message}"
+ msg = "Proxy error when proxying to #{url}: #{e.class}: #{e.message}"
env["rack.errors"].puts msg
env["rack.errors"].puts e.backtrace.map { |l| "\t" + l }
env["rack.errors"].flush
@@ -30,13 +28,12 @@ def proxy(hostname, port=80, username=nil, password=nil)
end
def call(env)
- req = Rack::Auth::Basic::Request.new(env)
- api_key = req.credentials[1]
- app_name = req.path_info[/^(.+?)\.git/, 1]
- receiver = ensure_receiver(app_name, api_key)
+ api_key = Rack::Auth::Basic::Request.new(env).credentials[1]
+ app_name = env["REQUEST_PATH"][/^(.+?)\.git/, 1]
+ receiver_url = ensure_receiver(app_name, api_key)
- puts "call app_name=#{app_name} api_key=#{api_key} receiver=#{receiver}"
- proxy(receiver)
+ puts "call app_name=#{app_name} api_key=#{api_key} receiver=#{receiver_url}"
+ proxy(env, receiver_url)
end
def ensure_receiver(app_name, api_key)
@@ -47,7 +44,7 @@ def receiver_config
# TODO: get release_url, repo get/put urls from core
{ "REDIS_URL" => ENV["REDIS_URL"],
"REPLY_KEY" => "launched.#{@uuid.generate}",
- "REPO_GET_URL" => "http://p.hagelb.org/hooke.bundle",
+ "REPO_GET_URL" => "http://p.hagelb.org/sokoban.bundle",
}
end
View
2  lib/sokoban/receiver.rb
@@ -62,7 +62,7 @@ def route(req_method, req_path)
def reply
host = UDPSocket.open { |s| s.connect("64.233.187.99", 1); s.addr.last }
- reply = JSON.encode({:host => host, :port => ENV["PORT"]})
+ reply = JSON.unparse({:host => host, :port => ENV["PORT"]})
Redis.new(:url => ENV["REDIS_URL"]).lpush(ENV["REPLY_KEY"], reply)
end
Please sign in to comment.
Something went wrong with that request. Please try again.