connection_custom.rb 766 B

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