2

I'm working with em-http, but I cannot get HTTPS(SSL) connection behind proxy. Here is my code.

require 'eventmachine'
require 'em-http'

url = "https://twitter.com/"
opts = {
  :proxy => { :host => 'my.proxy', :port => 8080 }
}

EventMachine.run do
  http = EventMachine::HttpRequest.new(url, opts).get
  http.callback {
    puts http.response
    EventMachine.stop
  }
end

This code works without errors, but it does nothing and does not quit from eventmachine main loop.

When I try it under conditions like below, my app can connect to the target.

  • outside proxy / via HTTPS
  • behind proxy / via HTTP

I can also get response using curl behind proxy.

curl "https://twitter.com/"

What's wrong with my code?

1
  • You could consider adding a timeout to the get request, so that at least the app doesn't hang forever. Change your line to read http = EventMachine::HttpRequest.new(url, opts).get, :timeout => 15 Commented May 10, 2012 at 10:39

3 Answers 3

1

I had the same problem today, I was unable to get the proxied ssl requests to work with my http proxy but I was able to get it to work with a socks5 proxy:

:proxy => { :host => 'my.proxy', :port => 8080, :type => :socks5 }
Sign up to request clarification or add additional context in comments.

Comments

1

Change the call:

http = EventMachine::HttpRequest.new(url).get opts

1 Comment

It would be helpful if you could explain a bit more why this works.
0

Specify an errback. Your code will then exit the event loop and also print any problems the proxy request may be having:

http.errback {
  p http.response_header.status
  p http.response_header
  p http.response

  EventMachine.stop
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.