connection_custom.rb 689 B

123456789101112131415161718192021
  1. # file is based on Twitter::Streaming::Connection, needed to get custom_connection_handle
  2. # to close connection after config has changed
  3. class Twitter::Streaming::ConnectionCustom < Twitter::Streaming::Connection
  4. def stream(request, response)
  5. client_context = OpenSSL::SSL::SSLContext.new
  6. @client = @tcp_socket_class.new(Resolv.getaddress(request.uri.host), request.uri.port)
  7. ssl_client = @ssl_socket_class.new(@client, client_context)
  8. ssl_client.connect
  9. request.stream(ssl_client)
  10. while body = ssl_client.readpartial(1024) # rubocop:disable Lint/AssignmentInCondition
  11. response << body
  12. end
  13. end
  14. def custom_connection_handle
  15. @client
  16. end
  17. end