class HttpStreamFormat

The HttpStreamFormat class is the format used to publish messages to HTTP stream clients connected to a GRIP proxy.

Attributes

close[RW]
content[RW]

Public Class Methods

new(content=nil, close=false) click to toggle source

Initialize with either the message content or a boolean indicating that the streaming connection should be closed. If neither the content nor the boolean flag is set then an error will be raised.

# File lib/httpstreamformat.rb, line 20
def initialize(content=nil, close=false)
  @content = content
  @close = close
  if !@close and @content.nil?
    raise 'Content not set'
  end
end

Public Instance Methods

export() click to toggle source

Exports the message in the required format depending on whether the message content is binary or not, or whether the connection should be closed.

# File lib/httpstreamformat.rb, line 36
def export
  out = Hash.new
  if @close
    out['action'] = 'close'
  else
    if @content.clone.force_encoding("UTF-8").valid_encoding?
      out['content'] = @content
    else
      out['content-bin'] = Base64.encode64(@content)
    end
  end
  return out
end
name() click to toggle source

The name used when publishing this format.

# File lib/httpstreamformat.rb, line 29
def name
  return 'http-stream'
end