Created
March 2, 2011 07:45
-
-
Save rummelonp/850616 to your computer and use it in GitHub Desktop.
特定のドメインへのリクエストをローカルに転送
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
#!/usr/bin/env ruby | |
require 'webrick' | |
require 'webrick/httpproxy' | |
require 'uri' | |
require 'open-uri' | |
handler = Proc.new() do |req, res| | |
if req.host == 'target.example.com' | |
open "http://127.0.0.1:3000#{req.path}" | |
end | |
end | |
server = WEBrick::HTTPProxyServer.new( | |
BindAddress: '127.0.0.1', | |
Port: 8080, | |
Logger: WEBrick::Log::new($stderr, WEBrick::Log::DEBUG), | |
ProxyVia: false, | |
ProxyContentHandler: handler | |
) | |
Signal.trap('INT') do | |
server.shutdown | |
end | |
server.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment