response

Function response 

Source
pub fn response<'q, 'r>(
    query: &'q [u8],
    buffer: &'r mut dyn Buffer,
    udp: bool,
) -> Result<Option<(Message<'q>, MessageBuilder<'r, Sink<'r>, QdSection>)>, ResponseError>
Expand description

Starts building a new response (QR=1) for the given query (QR=0).

Returns the query view and response builder, or writes an error response to the given buffer and returns None, or returns a MessageError if either of those fail.

The algorithm is as follows:

  1. If the query header is malformed, return an empty response with RCODE = FormErr
  2. Start a new response with the same ID + OPCODE + RD, defaulting to RCODE = NotImp
  3. If the query is well-formed and its EDNS version (if any) supported, return Ok(Some())
  4. If the query has any EDNS OPT RR, add EDNS OPT RR to the response
  5. If the query EDNS version is unimplemented, finish the response with RCODE = BADVERS
  6. If the query is otherwise malformed, finish the response with RCODE = FormErr
  7. Return Ok(None)