Class: SimpleStream::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_stream/connection.rb

Instance Method Summary collapse

Instance Method Details

#stream(request, response) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
# File 'lib/simple_stream/connection.rb', line 6

def stream(request, response)
  client_context = OpenSSL::SSL::SSLContext.new
  client = TCPSocket.new(Resolv.getaddress(request.uri.host), request.uri.port)
  ssl_client = OpenSSL::SSL::SSLSocket.new(client, client_context)
  ssl_client.connect
  request.stream(ssl_client)

  while body = ssl_client.readpartial(1024)
    response << body
  end
end