Skip to content

Instantly share code, notes, and snippets.

@timblair
Created June 29, 2011 10:09
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 timblair/1053578 to your computer and use it in GitHub Desktop.
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.
# 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