Skip to content

sonots/resolver_replace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

resolver-replace

Replace the DNS resolver.

Installation

gem install resolver_replace

How it works

Ruby comes with a pure Ruby replacement, resolv-replace. It replaces the libc resolver with the built-in Resolv class which is a thread-aware DNS resolver library.

This gem works similarly, but allows to replace the resolver with your favorite resolver.

How to use

For example, if you want to replace the resolver with Resolv::DNS, write as followings:

require 'resolv' # Resolv::DNS
require 'resolver_replace' # ResolverReplace

resolver = Resolv::DNS.new(:nameserver => ['210.251.121.21'],
                           :search => ['ruby-lang.org'],
                           :ndots => 1)

ResolverReplace.register!(
  getaddress: Proc.new {|host| resolver.getaddress(host) },
  getaddresses: Proc.new {|host| resolver.getaddresses(host) },
  error_class: Resolv::ResolvError,
)

Plugin

Some gems like mysql2 implement its connection in its C extension without using ruby library. In such case, another monkeypatch must be applied. A plugin scheme of ResolveReplace is ready for such case.

The mysql2 plugin is available for example. Use as followings:

ResolverReplace.load_plugin('mysql2')
ResolverReplace.register!(
  getaddress: Proc.new {|host| resolver.getaddress(host) },
  getaddresses: Proc.new {|host| resolver.getaddresses(host) },
  error_class: Resolv::ResolvError,
)

ChangeLog

See CHANGELOG.md for details.

See Also

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Copyright

Copyright (c) 2014 Naotoshi Seo. See LICENSE.txt for details.

About

Replace the DNS resolver

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages