You are not logged in.
Pages: 1

Someone in irc was asking about a simple http proxy the other day. I scratched around in some ruby, and came up with a *very* simple one..in 15 lines of code. Yeah, I know..I am prone to verbosity..
Something to fiddle with, in any regard.  
super simple http-proxy
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline

A slightly more complete version. Plays a bit nicer with things like wget and links.
simple http-proxy
Lookout! code bloat! feature creep!
 
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
I raise you one and give you one in python in 4 lines.
https://iphitus.loudas.com/arch/proxy/5lineproxy.py
or the slightly more readable version
https://iphitus.loudas.com/arch/proxy/9lineproxy.py
though it still doesnt do http post. which means you cant do forums, etc, im fiddling on one that does http post now...
Offline

well, like i said, mine was a tad verbose. I actual was outputting useful text. 
EDIT: Your links dont go anywhere iphitus..
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
well, like i said, mine was a tad verbose. I actual was outputting useful text.
meh, didnt have anything else to do  I'm trying to make mine do POST requests.. which isnt easy.
 I'm trying to make mine do POST requests.. which isnt easy.
Offline

yeah. get is pretty easy. post, and cookies...that would be harder.
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
Hi,
basic post-support:
#!/usr/bin/env ruby
require 'socket'
require 'open-uri'
server = TCPServer.new('127.0.0.1', 9090)
while (session = server.accept)
  request = ""
  response = ""
    
  while (r = session.gets) and r.strip.any?
    request += r
  end
  puts request
  r_type, url_request = (request.split(/ /))
  begin
    case r_type
      when /POST/
        uri = URI.parse(url_request)                
                if uri.is_a?(URI::HTTPS)
                  raise "sorry, no https possiblen"
        end
        content_length = request.scan(/Content-Length: ([0-9]+)rn/i).flatten[0].to_i
        content = session.read(content_length)
                Net::HTTP.start(uri.host, uri.port) do |http|
                  response = http.post(uri.path,content).body
        end
      when /GET/
        open(url_request) do |file|
          response = file.read
        end
      else
        raise "unknown request-type: #{r_type}"
        end
  rescue => e
    response = "Error: "+e.to_s
  end
  session.print response
  session.close
endOffline
oh, that's just mean, I still havnt got my post support working.
Offline

I just want Rails :cry:
Mr Green
Offline
I just want Rails :cry:
In what way would you use rails to write a proxy?  
Offline

Mr Green wrote:I just want Rails :cry:
In what way would you use rails to write a proxy?
:oops: threading nappin' sorry
Mr Green
Offline
Btw. this proxy runs great on my linksys wrt54gs with openwrt firmware. I tried to run rails there too. But no chance, it eats way too much resources. Sure it works, but just about 0.2 pages per second :shock:
Offline

Btw. this proxy runs great on my linksys wrt54gs with openwrt firmware. I tried to run rails there too. But no chance, it eats way too much resources. Sure it works, but just about 0.2 pages per second :shock:
LOL, you running OpenWrt?
It's kinda funny you're using cactus' mini-proxy on your router 8)
Offline
yeah, this little box can be almost everything you want it to be when using openwrt.
Offline


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline

thanks to jochen, i added post support. Works with both post and get urls..
like post to get type urls even 
eg. http://localhost/index.php?type=no
http-proxy.rb
heh..i might try adding cookie support next. 
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline

cookie support is mostly working. Not sure if it allows creating a new cookie, or if it just uses an old cookie.
I may add some threading soon, as it only requests and returns pages sequentially.
heh. nothing like wasting time on silly code. 
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
For threading I would suggest subclassing from GServer http://www.ruby-doc.org/stdlib/libdoc/g … erver.html
Offline

oooh.
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
Pages: 1