refactor: fully move IDNAResolver to netxlite (#433)

We started doing this in https://github.com/ooni/probe-cli/pull/432.

This work is part of https://github.com/ooni/probe/issues/1733.
This commit is contained in:
Simone Basso 2021-08-17 11:02:12 +02:00 committed by GitHub
commit bef5b87a8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 84 additions and 120 deletions

View file

@ -1,34 +1,11 @@
package resolver
import (
"context"
"golang.org/x/net/idna"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
// IDNAResolver is to support resolving Internationalized Domain Names.
// See RFC3492 for more information.
type IDNAResolver struct {
Resolver
}
type IDNAResolver = netxlite.ResolverIDNA
// LookupHost implements Resolver.LookupHost
func (r IDNAResolver) LookupHost(ctx context.Context, hostname string) ([]string, error) {
host, err := idna.ToASCII(hostname)
if err != nil {
return nil, err
}
return r.Resolver.LookupHost(ctx, host)
}
// Network implements Resolver.Network.
func (r IDNAResolver) Network() string {
return "idna"
}
// Address implements Resolver.Address.
func (r IDNAResolver) Address() string {
return ""
}
var _ Resolver = IDNAResolver{}
var _ Resolver = &IDNAResolver{}