mirror of
https://github.com/coredns/coredns.git
synced 2026-08-20 23:08:28 -04:00
plugin/forward: Add http(2) host/authority header and TO server resolution (#8233)
This commit is contained in:
@@ -25,11 +25,11 @@ const Path = "/dns-query"
|
||||
// The URL should not have a path, so please exclude /dns-query. The URL will
|
||||
// be prefixed with https:// by default, unless it's already prefixed with
|
||||
// either http:// or https://.
|
||||
func NewRequest(method, url string, m *dns.Msg) (*http.Request, error) {
|
||||
return NewRequestWithContext(context.Background(), method, url, m)
|
||||
func NewRequest(method, url, host string, m *dns.Msg) (*http.Request, error) {
|
||||
return NewRequestWithContext(context.Background(), method, url, host, m)
|
||||
}
|
||||
|
||||
func NewRequestWithContext(ctx context.Context, method, url string, m *dns.Msg) (*http.Request, error) {
|
||||
func NewRequestWithContext(ctx context.Context, method, url, host string, m *dns.Msg) (*http.Request, error) {
|
||||
buf, err := m.Pack()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -55,6 +55,7 @@ func NewRequestWithContext(ctx context.Context, method, url string, m *dns.Msg)
|
||||
|
||||
req.Header.Set("Content-Type", MimeType)
|
||||
req.Header.Set("Accept", MimeType)
|
||||
req.Host = host
|
||||
return req, nil
|
||||
|
||||
case http.MethodPost:
|
||||
@@ -70,6 +71,7 @@ func NewRequestWithContext(ctx context.Context, method, url string, m *dns.Msg)
|
||||
|
||||
req.Header.Set("Content-Type", MimeType)
|
||||
req.Header.Set("Accept", MimeType)
|
||||
req.Host = host
|
||||
return req, nil
|
||||
|
||||
default:
|
||||
|
||||
@@ -25,7 +25,7 @@ func TestDoH(t *testing.T) {
|
||||
m := new(dns.Msg)
|
||||
m.SetQuestion("example.org.", dns.TypeDNSKEY)
|
||||
|
||||
req, err := NewRequest(test.method, test.url, m)
|
||||
req, err := NewRequest(test.method, test.url, "example.org", m)
|
||||
if err != nil {
|
||||
t.Errorf("Failure to make request: %s", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user