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
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
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
10 11 12 |
# File 'lib/sse_client/streaming_http.rb', line 10 def headers @headers end |
#status ⇒ Object (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
#close ⇒ Object
20 21 22 23 |
# File 'lib/sse_client/streaming_http.rb', line 20 def close @socket.close if @socket @socket = nil end |
#read_all ⇒ Object
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_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.
27 28 29 |
# File 'lib/sse_client/streaming_http.rb', line 27 def read_lines @reader.read_lines end |