Class: Lightstreamer::StreamConnectionHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/lightstreamer/stream_connection_header.rb

Overview

Helper class that processes the contents of the header returned by the server when a new stream connection is created or an existing session is bound to.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStreamConnectionHeader

Returns a new instance of StreamConnectionHeader.



9
10
11
12
# File 'lib/lightstreamer/stream_connection_header.rb', line 9

def initialize
  @data = {}
  @lines = []
end

Instance Attribute Details

#errorProtocolError, RequestError (readonly)

Returns If there was an error in the header then this value will be set to the error instance that should be raised in response.

Returns:

  • (ProtocolError, RequestError)

    If there was an error in the header then this value will be set to the error instance that should be raised in response.



7
8
9
# File 'lib/lightstreamer/stream_connection_header.rb', line 7

def error
  @error
end

Instance Method Details

#[](item_name) ⇒ String?

Returns the value for the item with the specified name in this header, or nil if no item with the specified name was part of this header

Parameters:

  • item_name (String)

    The name of the item to return the header value for.

Returns:

  • (String, nil)

    The value of the item as specified in this header, or nil if the item name was not specified in this header.



43
44
45
# File 'lib/lightstreamer/stream_connection_header.rb', line 43

def [](item_name)
  @data[item_name]
end

#process_header_line(line) ⇒ Boolean

Processes a single line of header information. The return value indicates whether further data is required in order to complete the header.

Parameters:

  • line (String)

    The line of header data to process.

Returns:

  • (Boolean)

    Whether the header is still incomplete and requires further data.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lightstreamer/stream_connection_header.rb', line 20

def process_header_line(line)
  @lines << line

  unless %w(OK ERROR).include? @lines.first
    @error = RequestError.new line
    return false
  end

  return true if @lines.first == 'OK' && !line.empty?
  return true if @lines.first == 'ERROR' && @lines.size < 3

  parse_header

  false
end