Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only use dns cache if specified #83

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func CacheLookup(recordType, hostname string) ([]net.IP, error) {
return ips, nil
}

// Lookup looksup the record using Go's default resolver
// Lookup looks up the record using Go's default resolver
func Lookup(recordType, hostname string) ([]net.IP, error) {
host := hostname
if url, err := url.Parse(hostname); err != nil {
Expand Down
8 changes: 5 additions & 3 deletions http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,13 @@ func (c *Client) roundTrip(r *Request) (resp *Response, err error) {
} else if h := r.getHeader("Host"); h != "" {
host = h
} else {
host = r.url.Host
host = r.url.Hostname()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Host would be localhost:port and DNS lookup would take about 3-4 seconds before failing.

}

if ips, _ := dns.CacheLookup("A", host); len(ips) > 0 {
host = ips[0].String()
if c.cacheDNS {
if ips, _ := dns.CacheLookup("A", host); len(ips) > 0 {
host = ips[0].String()
}
}

req, err := http.NewRequestWithContext(r.ctx, r.method, r.url.String(), r.body)
Expand Down
Loading