class HttpResponseFormat

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

Attributes

body[RW]
code[RW]
headers[RW]
reason[RW]

Public Class Methods

new(code=nil, reason=nil, headers=nil, body=nil) click to toggle source

Initialize with the message code, reason, headers, and body to send to the client when the message is publishing.

# File lib/httpresponseformat.rb, line 21
def initialize(code=nil, reason=nil, headers=nil, body=nil)
  @code = code
  @reason = reason
  @headers = headers
  @body = body
end

Public Instance Methods

export() click to toggle source

Export the message into the required format and include only the fields that are set. The body is exported as base64 if the text is encoded as binary.

# File lib/httpresponseformat.rb, line 36
def export
  out = Hash.new
  if !@code.nil?
    out['code'] = @code
  end
  if !@reason.nil?
    out['reason'] = @reason
  end
  if !@headers.nil? and @headers.length > 0
    out['headers'] = @headers
  end
  if !@body.nil?
    if @body.clone.force_encoding("UTF-8").valid_encoding?   
      out['body'] = @body
    else
      out['body-bin'] = Base64.encode64(@body)
    end
  end
  return out
end
name() click to toggle source

The name used when publishing this format.

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