-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoH.php
More file actions
66 lines (59 loc) · 1.53 KB
/
DoH.php
File metadata and controls
66 lines (59 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace Utopia\DNS\Resolver;
use Utopia\DNS\DoHClient;
use Utopia\DNS\Message;
use Utopia\DNS\Resolver;
/**
* DNS over HTTPS (DoH) Resolver
*
* A resolver that forwards DNS queries to a DoH server over HTTPS.
* Implements RFC 8484 for DNS queries over HTTP/HTTPS.
*/
class DoH implements Resolver
{
protected DoHClient $client;
protected string $endpoint;
/**
* Create a new DoH resolver
*
* @param string $endpoint DoH endpoint URL (e.g., https://cloudflare-dns.com/dns-query)
* @param int $timeout Request timeout in seconds
* @param string $method HTTP method to use (GET or POST)
*/
public function __construct(
string $endpoint,
int $timeout = 5,
string $method = DoHClient::METHOD_POST
) {
$this->endpoint = $endpoint;
$this->client = new DoHClient($endpoint, $timeout, $method);
}
/**
* Resolve DNS query by forwarding to the DoH server
*
* @param Message $query The DNS query message
* @return Message The DNS response message
*/
public function resolve(Message $query): Message
{
return $this->client->query($query);
}
/**
* Get the name of the resolver
*
* @return string The resolver name
*/
public function getName(): string
{
return "DoH ($this->endpoint)";
}
/**
* Get the DoH client instance
*
* @return DoHClient The client instance
*/
public function getClient(): DoHClient
{
return $this->client;
}
}