Created
June 29, 2011 10:09
-
-
Save timblair/1053578 to your computer and use it in GitHub Desktop.
Simple HTTP proxy for strangely formatted localhost requests, as used by certain native mobile apps.
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
# Incredibly simple HTTP proxy that takes `GET` requests of the form | |
# | |
# http://127.0.0.1:12345/www.domain.com/path/to/resource | |
# | |
# and proxies to | |
# | |
# http://www.domain.com/path/to/resource | |
# | |
# All body content and headers are passed through untouched. | |
# | |
# Run using `shotgun` and choose your port: `$ shotgun -p 12345 proxy.rb` | |
require 'rubygems' | |
require 'sinatra' | |
require 'net/https' | |
require 'uri' | |
get '/*' do |path| | |
uri = URI.parse("http://#{params[:splat]}") | |
res = Net::HTTP.get_response(uri) | |
status res.code | |
res.each_header { |k,v| headers k => v } | |
body res.body | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment