@@ -153,18 +153,12 @@ func (p *dnsOverHTTPS) Address() string { return p.addrRedacted }
153153
154154// Exchange implements the [Upstream] interface for *dnsOverHTTPS.
155155func (p * dnsOverHTTPS ) Exchange (req * dns.Msg ) (resp * dns.Msg , err error ) {
156- // In order to maximize HTTP cache friendliness, DoH clients using media
157- // formats that include the ID field from the DNS message header, such as
158- // "application/dns-message", SHOULD use a DNS ID of 0 in every DNS request.
159- //
160- // See https://www.rfc-editor.org/rfc/rfc8484.html.
161- id := req .Id
162- req .Id = 0
163156 defer func () {
164- // Restore the original ID to not break compatibility with proxies.
165- req .Id = id
157+ // Restore the original request ID, since it was set to 0.
158+ //
159+ // See https://www.rfc-editor.org/rfc/rfc8484.html.
166160 if resp != nil {
167- resp .Id = id
161+ resp .Id = req . Id
168162 }
169163 }()
170164
@@ -253,6 +247,14 @@ func (p *dnsOverHTTPS) exchangeHTTPSClient(
253247 return nil , fmt .Errorf ("packing message: %w" , err )
254248 }
255249
250+ // In order to maximize HTTP cache friendliness, DoH clients using media
251+ // formats that include the ID field from the DNS message header, such as
252+ // "application/dns-message", SHOULD use a DNS ID of 0 in every DNS request.
253+ //
254+ // See https://www.rfc-editor.org/rfc/rfc8484.html.
255+ buf [0 ] = 0
256+ buf [1 ] = 0
257+
256258 // It appears, that GET requests are more memory-efficient with Golang
257259 // implementation of HTTP/2.
258260 method := http .MethodGet
0 commit comments