Skip to content

Commit

Permalink
Add cloudflare DNS over HTTP example.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Apr 11, 2018
1 parent 249f223 commit cfc2ac2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/cloudflare.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env ruby

gem 'async'
gem 'async-http'
gem 'trenni'

require 'async/reactor'
require 'async/http/client'
require 'async/http/url_endpoint'

require 'trenni/uri'

# Async.logger.level = Logger::DEBUG

endpoint = Async::HTTP::URLEndpoint.parse("https://cloudflare-dns.com/dns-query")
client = Async::HTTP::Client.new(endpoint)

Async::Reactor.run do |task|
request_uri = Trenni::URI(endpoint.url.request_uri, ct: "application/dns-json", name: "microsoft.com", type: "MX")

puts "GET #{request_uri}"
response = client.get(request_uri.to_s, {})

puts "#{response.status} #{response.version} #{response.headers.inspect}"
puts response.read.inspect
end

0 comments on commit cfc2ac2

Please sign in to comment.