No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

doh-query.R 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #' Make a DoH Request (POST/wireformat)
  2. #'
  3. #' Issue a `POST` wireformat query of type `type` for `name` to
  4. #' the DoH endpoint specified at `server_path`.
  5. #'
  6. #' @param name name to query for
  7. #' @param type DNS query type (defaults to "`A`")
  8. #' @param server_path full URL path to the DoH server quer endpoint (defaults to Quad9).
  9. #' @return `NULL` (if the query failed) or a `data.frame` (tibble)
  10. #' @references <https://tools.ietf.org/id/draft-ietf-doh-dns-over-https-05.html>
  11. #' @export
  12. #' @examples
  13. #' doh_post("rud.is", "A")
  14. doh_post <- function(name, type = "A", server_path = "https://dns.quad9.net/dns-query") {
  15. DNSRecord$new()$question(
  16. qname = tolower(name[1]),
  17. qtype = toupper(type[1]),
  18. qclass = "IN"
  19. ) -> q
  20. # now, send it off to the server
  21. httr::POST(
  22. url = server_path[1],
  23. httr::add_headers(
  24. `Content-Type` = "application/dns-message",
  25. `Accept` = "application/dns-message"
  26. ),
  27. encode = "raw",
  28. body = q$pack()
  29. ) -> res
  30. httr::stop_for_status(res)
  31. res <- int_dns_wire_to_list(httr::content(res, as = "raw"))
  32. if (length(res)) {
  33. out <- jsonlite::fromJSON(res)
  34. # class(out) <- c("gdns_response", "list")
  35. out
  36. } else {
  37. NULL
  38. }
  39. }