plugin/forward: Add http(2) host/authority header and TO server resolution (#8233)

This commit is contained in:
llucas
2026-07-22 19:07:09 -07:00
committed by GitHub
parent 56f7c09311
commit 73d1eacf87
9 changed files with 83 additions and 32 deletions

View File

@@ -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:

View File

@@ -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)
}