Skip to content

Instantly share code, notes, and snippets.

@pwhelan
Created July 5, 2012 08:09
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 pwhelan/3052196 to your computer and use it in GitHub Desktop.
Save pwhelan/3052196 to your computer and use it in GitHub Desktop.
ProxyApp for connecting Pow to PHP
require 'net/http'
class ProxyApp
def call(env)
begin
request = Rack::Request.new(env)
headers = {}
env.each do |key, value|
if key =~ /^http_(.*)/i
headers[$1] = value
end
end
http = Net::HTTP.new("localhost", 8080)
http.start do |http|
headers['X-Content-Type'] = request.content_type
response = http.send_request(request.request_method, '/~madjester/clickfortime.com' + request.fullpath, request.body.read, headers)
resp_code, resp_headers, resp_body = response.code, response.to_hash, response.body
# Research showed that browsers were choking on this for some reason.
# Probably not the be-all-end-all solution, but works for local development thus far.
resp_headers.delete('transfer-encoding')
[resp_code, resp_headers, [resp_body]]
end
rescue Errno::ECONNREFUSED
[500, {}, ["Server is down, try $ sudo apachectl start"]]
end
end
end
run ProxyApp.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment