httpClient = $artax; $this->nameserver = $nameserver; if ($nameserver->getType() !== Nameserver::GOOGLE_JSON) { $this->encoder = (new EncoderFactory)->create(); $this->decoder = (new DecoderFactory)->create(); } else { $this->encoder = (new QueryEncoderFactory)->create(); $this->decoder = (new JsonDecoderFactory)->create(); } parent::__construct(); } protected function resolve(Message $message): Promise { $id = $message->getID(); switch ($this->nameserver->getType()) { case Nameserver::RFC8484_GET: $data = $this->encoder->encode($message); $request = (new Request($this->nameserver->getUri().'?'.\http_build_query(['dns' => \base64_encode($data), 'ct' => 'application/dns-message']), "GET")) ->withHeader('accept', 'application/dns-message') ->withHeaders($this->nameserver->getHeaders()); break; case Nameserver::RFC8484_POST: $data = $this->encoder->encode($message); $request = (new Request($this->nameserver->getUri(), "POST")) ->withBody($data) ->withHeader('content-type', 'application/dns-message') ->withHeader('accept', 'application/dns-message') ->withHeaders($this->nameserver->getHeaders()); break; case Nameserver::GOOGLE_JSON: $data = $this->encoder->encode($message); $request = (new Request($this->nameserver->getUri().'?'.$data, "GET")) ->withHeader('accept', 'application/dns-json') ->withHeaders($this->nameserver->getHeaders()); break; } $response = $this->httpClient->request($request); return call(function () use ($response, $id) { $response = yield (yield $response)->getBody(); switch ($this->nameserver->getType()) { case Nameserver::RFC8484_GET: case Nameserver::RFC8484_POST: return $this->decoder->decode($response); case Nameserver::GOOGLE_JSON: return $this->decoder->decode($response, $id); } }); } }