fix: doh use NewRequestWithContext and batchExchange don't wait cancel finish

This commit is contained in:
wwqgtxx
2022-11-19 09:43:31 +08:00
parent 23f286f24e
commit f00dc69bb6
2 changed files with 23 additions and 3 deletions

View File

@ -208,14 +208,13 @@ func (doh *dnsOverHTTPS) exchangeHTTPSClient(
}
doh.url.RawQuery = fmt.Sprintf("dns=%s", base64.RawURLEncoding.EncodeToString(buf))
httpReq, err := http.NewRequest(method, doh.url.String(), nil)
httpReq, err := http.NewRequestWithContext(ctx, method, doh.url.String(), nil)
if err != nil {
return nil, fmt.Errorf("creating http request to %s: %w", doh.url, err)
}
httpReq.Header.Set("Accept", "application/dns-message")
httpReq.Header.Set("User-Agent", "")
_ = httpReq.WithContext(ctx)
httpResp, err := client.Do(httpReq)
if err != nil {
return nil, fmt.Errorf("requesting %s: %w", doh.url, err)