Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 0.58 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # Incredibly simple HTTP proxy that takes `GET` requests of the form
  2. #
  3. #     http://127.0.0.1:12345/www.domain.com/path/to/resource
  4. #
  5. # and proxies to
  6. #
  7. #     http://www.domain.com/path/to/resource
  8. #
  9. # All body content and headers are passed through untouched.
  10. #
  11. # Run using `shotgun` and choose your port: `$ shotgun -p 12345 proxy.rb`
  12.  
  13. require 'rubygems'
  14. require 'sinatra'
  15. require 'net/https'
  16. require 'uri'
  17.  
  18. get '/*' do |path|
  19.   uri = URI.parse("http://#{params[:splat]}")
  20.   res = Net::HTTP.get_response(uri)
  21.   status res.code
  22.   res.each_header { |k,v| headers k => v }
  23.   body res.body
  24. end