Class: SSE::StreamingHTTPConnection
- Inherits:
-
Object
- Object
- SSE::StreamingHTTPConnection
- 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
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(uri, proxy, headers, connect_timeout, read_timeout) ⇒ StreamingHTTPConnection
constructor
A new instance of StreamingHTTPConnection.
-
#read_all ⇒ Object
Consumes the entire response body and returns it.
-
#read_lines ⇒ Object
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.
Constructor Details
#initialize(uri, proxy, headers, connect_timeout, read_timeout) ⇒ StreamingHTTPConnection
13 14 15 16 17 18 19 20 |
# File 'lib/sse_client/streaming_http.rb', line 13 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 @closed = Concurrent::AtomicBoolean.new(false) end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
11 12 13 |
# File 'lib/sse_client/streaming_http.rb', line 11 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
11 12 13 |
# File 'lib/sse_client/streaming_http.rb', line 11 def status @status end |
Instance Method Details
#close ⇒ Object
22 23 24 25 26 27 |
# File 'lib/sse_client/streaming_http.rb', line 22 def close if @closed.make_true @socket.close if @socket @socket = nil end end |
#read_all ⇒ Object
Consumes the entire response body and returns it.
36 37 38 |
# File 'lib/sse_client/streaming_http.rb', line 36 def read_all @reader.read_all end |
#read_lines ⇒ Object
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.
31 32 33 |
# File 'lib/sse_client/streaming_http.rb', line 31 def read_lines @reader.read_lines end |