Class: Latte::Response

Inherits:
Object show all
Defined in:
lib/latte/response.rb

Defined Under Namespace

Classes: Answer, BigEndianRecord, Question, RecordParser, ResponseHeader

Instance Method Summary collapse

Instance Method Details

#add(record) ⇒ Object



178
179
180
181
182
183
# File 'lib/latte/response.rb', line 178

def add record
  parser = RecordParser.new record
  parser.execute
  record = parser.record
  answers << record
end

#answersObject



65
66
67
# File 'lib/latte/response.rb', line 65

def answers
  @answers ||= [ ]
end

#headerObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/latte/response.rb', line 40

def header
  ResponseHeader.new.tap { |h|
    h.id = query.id
    h.qr = 1 # I'm a response
    h.opcode = 0 # I'm a standard query
    h.aa = 0 # I'm not authoritative
    h.tc = 0 # I wasn't truncated
    h.rd = 0 # Please don't recursively query
    h.ra = 0 # Recursion isn't welcome here
    h.rcode = 0 # There are no errors here
    h.qdcount = 1 # I'm answering one query
    h.ancount = answers.size # The number of answer records I'm sending
    h.nscount = 0 # There are 0 NS records in the authority part
    h.arcount = 0 # How many additional records am I sending?
  }
end

#questionObject



57
58
59
60
61
62
63
# File 'lib/latte/response.rb', line 57

def question
  Question.new.tap { |q|
    q.qname = query.qname
    q.qtype = query.qtype
    q.qclass = query.qclass
  }
end

#to_sObject



185
186
187
188
189
# File 'lib/latte/response.rb', line 185

def to_s
  [ header, question, *answers ].map { |part|
    part.to_binary_s
  }.join ''
end