You are right, the wire format is not just the base64 encoded version of the domain name. The wire format for DNS over HTTP is a little more complicated than that. It consists of the following parts:
The first 2 bytes are the flags. These bits indicate the type of query, whether it is recursive or not, and other options.
The next 2 bytes are the number of questions. This is the number of domain names that are being queried.
The next 2 bytes are the number of answers. This is the number of answers that are expected in the response.
The next 2 bytes are the number of authority records.
The next 2 bytes are the number of additional records.
The questions are then listed, one per line. Each question consists of the following parts:
The domain name, encoded in base64.
The type of query, such as A for an IPv4 address or AAAA for an IPv6 address.
The class of the query, such as IN for the Internet class.
So, in the case of the query for www.example.com, the wire format would be:
- 0001 0000 # Flags: Recursive query
- 0001 0001 # Questions: 1
- 0000 0000 # Answers: 0
- 0000 0000 # Authority records: 0
- 0000 0000 # Additional records: 0
AAABAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB # Question: www.example.com (base64 encoded)
The AAABAAABAAAAAAAAA part is the base64 encoded version of the domain name, but it is prefixed with some padding bits. The padding bits are necessary to ensure that the length of the wire format is a multiple of 8 bytes.
I hope this explanation helps!
Here are some additional resources that you may find helpful: