Created
August 19, 2018 05:34
-
-
Save libkazz/462aa4a2c8f5640fab9d26c8eb4a744d to your computer and use it in GitHub Desktop.
proxy sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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