Skip to content

Instantly share code, notes, and snippets.

@libkazz
Created August 19, 2018 05:34
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 libkazz/462aa4a2c8f5640fab9d26c8eb4a744d to your computer and use it in GitHub Desktop.
Save libkazz/462aa4a2c8f5640fab9d26c8eb4a744d to your computer and use it in GitHub Desktop.
proxy sample
require 'rack-proxy'
module SimulationSample
class Proxy < Rack::Proxy
def rewrite_env(env)
env
end
end
def self.call(env)
uri = URI.parse(env['REQUEST_URI'])
if uri.query =~ %r{^u=(http.?://.*)}
target_uri = URI.parse($1)
proxy = Proxy.new(backend: target_uri.to_s, streaming: false)
env.each {|k,v| p [k,v] }
proxy.call('REQUEST_METHOD' => env['REQUEST_METHOD'],
'REQUEST_URI' => target_uri.path,
'QUERY_STRING' => target_uri.query,
'PATH_INFO' => target_uri.path,)
else
[404, {}, ["Not found"]]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment