Skip to main content

parse_doh_txt_answers

Function parse_doh_txt_answers 

Source
pub fn parse_doh_txt_answers(json: &Value) -> String
Expand description

PURE. From a Cloudflare/Google DoH JSON response, read the "Answer" array and concatenate the "data" field of every answer into one string.

DNS TXT values are transmitted as one or more length-prefixed character-strings (≤255 bytes each); DoH resolvers surface a multi-part TXT as "part-a" "part-b" inside a single "data" field, and split records may also appear as multiple Answer elements. In both cases the logical value is the pieces concatenated with no separator, so we:

  1. take each answer’s "data" string,
  2. strip the surrounding double-quotes and any internal " " string-boundary quotes, and
  3. concatenate everything into one string (which is then a valid _qdp.<domain> TXT value).

Missing / malformed answers are skipped; a body with no usable answers yields "".