Class: SSE::StreamingHTTPConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/sse_client/streaming_http.rb

Overview

Wrapper around a socket providing a simplified HTTP request-response cycle including streaming. The socket is created and managed by Socketry, which we use so that we can have a read timeout.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, proxy, headers, connect_timeout, read_timeout) ⇒ StreamingHTTPConnection

Returns a new instance of StreamingHTTPConnection.



12
13
14
15
16
17
18
# File 'lib/sse_client/streaming_http.rb', line 12

def initialize(uri, proxy, headers, connect_timeout, read_timeout)
  @socket = HTTPConnectionFactory.connect(uri, proxy, connect_timeout, read_timeout)
  @socket.write(build_request(uri, headers))
  @reader = HTTPResponseReader.new(@socket, read_timeout)
  @status = @reader.status
  @headers = @reader.headers
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



10
11
12
# File 'lib/sse_client/streaming_http.rb', line 10

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



10
11
12
# File 'lib/sse_client/streaming_http.rb', line 10

def status
  @status
end

Instance Method Details

#closeObject



20
21
22
23
# File 'lib/sse_client/streaming_http.rb', line 20

def close
  @socket.close if @socket
  @socket = nil
end

#read_allObject

Consumes the entire response body and returns it.



32
33
34
# File 'lib/sse_client/streaming_http.rb', line 32

def read_all
  @reader.read_all
end

#read_linesObject

Generator that returns one line of the response body at a time (delimited by r, n, or rn) until the response is fully consumed or the socket is closed.



27
28
29
# File 'lib/sse_client/streaming_http.rb', line 27

def read_lines
  @reader.read_lines
end