em-http-request unexpected result when using tor as proxy

263 views Asked by At

I've created a gist which shows exactly what happens.
https://gist.github.com/4418148
I've tested a version which used ruby's 'net/http' library and 'socksify/http' and it worked perfect but if the EventMachine version returns an unexpected result.
The response in Tor Browser is correct but using EventMachine is not!

It return a response but it's not the same as returned response when you send the request via browser, net/http with or without proxy.

For convenience, I will also paste it here.

require 'em-http-request'

DEL = '-'*40
@results = 0

def run_with_proxy
  connection_opts = {:proxy => {:host => '127.0.0.1', :port => 9050, :type => :socks5}}
  conn = EM::HttpRequest.new("http://www.apolista.de/tegernsee/kloster-apotheke",       connection_opts)
  http = conn.get
  http.callback {
    if http.response.include? "Oops"
      puts "#{DEL}failed with proxy#{DEL}", http.response
    else
      puts "#{DEL}success with proxy#{DEL}", http.response
    end
    @results+=1
    EM.stop_event_loop if @results == 2
  }
end

def run_without_proxy
  conn = EM::HttpRequest.new("http://www.apolista.de/tegernsee/kloster-apotheke")
  http = conn.get
  http.callback {
    if http.response.include? "Oops"
      puts "#{DEL}failed without proxy#{DEL}", http.response
    else
      puts "#{DEL}success without proxy#{DEL}", http.response
    end
    @results+=1
    EM.stop_event_loop if @results == 2
  }
end

EM.run do
  run_with_proxy
  run_without_proxy
end

Appreciate any clarification.

0

There are 0 answers