MCPcopy
hub / github.com/AdguardTeam/dnsproxy / sendTestDoHMessage

Function sendTestDoHMessage

proxy/serverhttps_internal_test.go:362–413  ·  view source on GitHub ↗

sendTestDoHMessage sends the specified DNS message using client and returns the DNS response.

(
	t *testing.T,
	client *http.Client,
	m *dns.Msg,
	hdrs map[string]string,
)

Source from the content-addressed store, hash-verified

360// sendTestDoHMessage sends the specified DNS message using client and returns
361// the DNS response.
362func sendTestDoHMessage(
363 t *testing.T,
364 client *http.Client,
365 m *dns.Msg,
366 hdrs map[string]string,
367) (resp *dns.Msg) {
368 packed, err := m.Pack()
369 require.NoError(t, err)
370
371 u := url.URL{
372 Scheme: "https",
373 Host: tlsServerName,
374 Path: "/dns-query",
375 RawQuery: fmt.Sprintf("dns=%s", base64.RawURLEncoding.EncodeToString(packed)),
376 }
377
378 method := http.MethodGet
379 if _, ok := client.Transport.(*http3.Transport); ok {
380 // If we're using HTTP/3, use http3.MethodGet0RTT to force using 0-RTT.
381 method = http3.MethodGet0RTT
382 }
383
384 req, err := http.NewRequest(method, u.String(), nil)
385 require.NoError(t, err)
386
387 req.Header.Set("Content-Type", "application/dns-message")
388 req.Header.Set("Accept", "application/dns-message")
389
390 for k, v := range hdrs {
391 req.Header.Set(k, v)
392 }
393
394 httpResp, err := client.Do(req) // nolint:bodyclose
395 require.NoError(t, err)
396 testutil.CleanupAndRequireSuccess(t, httpResp.Body.Close)
397
398 require.True(
399 t,
400 httpResp.ProtoAtLeast(2, 0),
401 "the proto is too old: %s",
402 httpResp.Proto,
403 )
404
405 body, err := io.ReadAll(httpResp.Body)
406 require.NoError(t, err)
407
408 resp = &dns.Msg{}
409 err = resp.Unpack(body)
410 require.NoError(t, err)
411
412 return resp
413}
414
415// createTestHTTPClient creates an *http.Client that will be used to send
416// requests to the specified dnsProxy.

Callers 2

TestHttpsProxyFunction · 0.85
TestProxy_trustedProxiesFunction · 0.85

Calls 2

StringMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…