Sha256: 3c6fe196b6fa3098b3a1bb7d0269b99fbc56fab36588081e75220f408aa43a6c

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

require 'uri'

def getFromGlobalProxy(proxy,url,post=nil)

  proxy_addr = '127.0.0.1'
  proxy_port = proxy.port
  result=nil
  puts "TRYING PROXY #{proxy_addr} #{proxy_port}"
  origurl=url.dup
  url=URI.parse(url)
   
  origurl.gsub!(/http:\/\/[^\/]*/,'')
   
  Net::HTTP::Proxy(proxy_addr, proxy_port).start(url.host,url.port) {|http|
    puts "HTTP OPENED"
    begin
      #pp url.path.
      #path=url
      if post
        req = Net::HTTP::Post.new(origurl)
        #     req.basic_auth 'jack', 'pass'
        #     req.set_form_data({'from'=>'2005-01-01', 'to'=>'2005-03-31'}, ';')
        pp "POST",post
        req.set_form_data(post,";")
        #req.set_form_data({'from'=>'2005-01-01', 'to'=>'2005-03-31'}, ';')
        pp "POSTREQ",req.body
        #pp req
        #result=http.requestpost(req)
        result=http.request_post(origurl,post.map{|k,v|k+"="+v}.join(";"))

      else
        result=http.get(origurl)
      end
      pp "RESULT:",result,result.body
    rescue Object=>e
      pp e,e.backtrace
    end
    #     pp "PROXY_RESULT:",result
    #     pp result.body
  }
  result
end

class String
  def valid_html?
    self=~/html/i # FIXME
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
appswarm-0.0.1 lib/appswarm/proxy_testing.rb