class FCGI::ValuesRecord

Attributes

values[R]

Public Class Methods

new(type, id, values) click to toggle source
Calls superclass method FCGI::Record.new
# File lib/fcgi.rb, line 477
def initialize(type, id, values)
  super type, id
  @values = values
end
parse(id, body) click to toggle source
# File lib/fcgi.rb, line 439
def self.parse(id, body)
  new(id, parse_values(body))
end
parse_values(buf) click to toggle source
# File lib/fcgi.rb, line 443
def self.parse_values(buf)
  result = {}
  until buf.empty?
    name, value = *read_pair(buf)
    result[name] = value
  end
  result
end
read_length(buf) click to toggle source
# File lib/fcgi.rb, line 460
def self.read_length(buf)
  if buf[0].bytes.first >> 7 == 0
    buf.slice!(0,1)[0].bytes.first
  else
    buf.slice!(0,4).unpack('N')[0] & ((1<<31) - 1)
  end
end
read_pair(buf) click to toggle source
# File lib/fcgi.rb, line 452
def self.read_pair(buf)
  nlen = read_length(buf)
  vlen = read_length(buf)
  [buf.slice!(0, nlen), buf.slice!(0, vlen)]
end

Private Instance Methods

make_body() click to toggle source
# File lib/fcgi.rb, line 486
def make_body
  buf = ''
  @values.each do |name, value|
    buf << serialize_length(name.length)
    buf << serialize_length(value.length)
    buf << name
    buf << value
  end
  buf
end
serialize_length(len) click to toggle source
# File lib/fcgi.rb, line 497
def serialize_length(len)
  if len < 0x80
  then len.chr
  else [len | (1<<31)].pack('N')
  end
end