Sha256: 88d3243f5fc65ea68ec2a667b836a2cfc2a072dfbfe392880ab60289599088b9
Contents?: true
Size: 1.08 KB
Versions: 14
Compression:
Stored size: 1.08 KB
Contents
### # Open http://localhost:3000/test.php to trigger proxy ### class RackPhpProxy < Rack::Proxy def perform_request(env) request = Rack::Request.new(env) if request.path =~ %r{\.php} env["HTTP_HOST"] = ENV["HTTP_HOST"] ? URI(ENV["HTTP_HOST"]).host : "localhost" ENV["PHP_PATH"] ||= '/manual/en/tutorial.firstpage.php' # Rails 3 & 4 env["REQUEST_PATH"] = ENV["PHP_PATH"] || "/php/#{request.fullpath}" # Rails 5 and above env['PATH_INFO'] = ENV["PHP_PATH"] || "/php/#{request.fullpath}" env['content-length'] = nil super(env) else @app.call(env) end end def rewrite_response(triplet) status, headers, body = triplet # if you proxy depending on the backend, it appears that content-length isn't calculated correctly # resulting in only partial responses being sent to users # you can remove it or recalculate it here headers["content-length"] = nil triplet end end Rails.application.config.middleware.use RackPhpProxy, backend: ENV["HTTP_HOST"]='http://php.net', streaming: false
Version data entries
14 entries across 14 versions & 3 rubygems