Skip to content

Commit

Permalink
Clean up wikipedia example.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Feb 7, 2018
1 parent afd370e commit 2fd757b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions examples/wikipedia-dns.rb
Expand Up @@ -24,7 +24,6 @@
require 'rubydns'

require 'cgi'
require 'nokogiri'
require 'json'

require 'digest/md5'
Expand All @@ -46,7 +45,11 @@ def self.lookup(title, logger: nil)
response = client.get(url, {'Host' => ENDPOINT.hostname})
logger&.info "Got response #{response.inspect}."

return self.extract_summary(response.body).force_encoding('ASCII-8BIT')
if response.status == 301
return lookup(response.headers['HTTP_LOCATION'])
else
return self.extract_summary(response.body).force_encoding('ASCII-8BIT')
end
end

def self.summary_url(title)
Expand All @@ -67,6 +70,11 @@ def self.extract_summary(json_text)
class WikipediaDNS
Name = Resolv::DNS::Name
IN = Resolv::DNS::Resource::IN

INTERFACES = [
[:udp, '::', 5300],
[:tcp, '::', 5300],
]

def startup
# Don't buffer output (for debug purposes)
Expand All @@ -75,7 +83,7 @@ def startup
stats = { requested: 0 }

# Start the RubyDNS server
RubyDNS.run_server([[:udp, '0.0.0.0', 5300], [:tcp, '0.0.0.0', 5300]]) do
RubyDNS.run_server(INTERFACES) do
on(:start) do
# Process::Daemon::Privileges.change_user(RUN_AS)

Expand Down

0 comments on commit 2fd757b

Please sign in to comment.