Skip to content

Commit

Permalink
Merge pull request #34 from csnitker-godaddy/master
Browse files Browse the repository at this point in the history
Added option to disable referral lookup
  • Loading branch information
likexian committed May 4, 2023
2 parents 30f9adf + 8082fc7 commit f92c187
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.idea
19 changes: 15 additions & 4 deletions whois.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ var DefaultClient = NewClient()

// Client is whois client
type Client struct {
dialer proxy.Dialer
timeout time.Duration
elapsed time.Duration
disableStats bool
dialer proxy.Dialer
timeout time.Duration
elapsed time.Duration
disableStats bool
disableReferral bool
}

// Version returns package version
Expand Down Expand Up @@ -100,6 +101,12 @@ func (c *Client) SetDisableStats(disabled bool) *Client {
return c
}

// SetDisableReferral if set to true, will not query the referral server.
func (c *Client) SetDisableReferral(disabled bool) *Client {
c.disableReferral = disabled
return c
}

// Whois do the whois query and returns whois information
func (c *Client) Whois(domain string, servers ...string) (result string, err error) {
start := time.Now()
Expand Down Expand Up @@ -149,6 +156,10 @@ func (c *Client) Whois(domain string, servers ...string) (result string, err err
return
}

if c.disableReferral {
return
}

refServer, refPort := getServer(result)
if refServer == "" || refServer == server {
return
Expand Down
15 changes: 15 additions & 0 deletions whois_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package whois

import (
"errors"
"strings"
"testing"
"time"

Expand All @@ -34,6 +35,20 @@ func TestVersion(t *testing.T) {
assert.Contains(t, License(), "Apache License")
}

func TestClient_SetDisableReferral(t *testing.T) {
client := NewClient()

resp, err := client.Whois("likexian.com")
assert.Nil(t, err)
assert.Equal(t, strings.Count(resp, "Domain Name: LIKEXIAN.COM"), 2)

client.SetDisableReferral(true)

resp, err = client.Whois("likexian.com")
assert.Nil(t, err)
assert.Equal(t, strings.Count(resp, "Domain Name: LIKEXIAN.COM"), 1)
}

func TestWhoisFail(t *testing.T) {
tests := []struct {
domain string
Expand Down

0 comments on commit f92c187

Please sign in to comment.