def _make_get_path(self, content): params = utils.build_query_params(content) self.logger.debug('Query parameters: {}'.format(params)) params_str = urllib.parse.urlencode(params) if self.args.debug: url = utils.make_url(self.args.domain, self.args.uri) self.logger.debug('Sending {}?{}'.format(url, params_str)) return self.args.uri + '?' + params_str
async def make_request(self, addr, dnsq): # FIXME: maybe aioh2 should allow registering to connection_lost event # so we can find out when the connection get disconnected. if self.client is None or self.client._conn is None: await self.setup_client() headers = {'Accept': constants.DOH_MEDIA_TYPE} path = self.args.uri qid = dnsq.id dnsq.id = 0 body = b'' headers = [ (':authority', self.args.domain), (':method', self.args.post and 'POST' or 'GET'), (':scheme', 'h2'), ] if self.args.post: headers.append(('content-type', constants.DOH_MEDIA_TYPE)) body = dnsq.to_wire() else: params = utils.build_query_params(dnsq.to_wire()) self.logger.debug('Query parameters: {}'.format(params)) params_str = urllib.parse.urlencode(params) if self.args.debug: url = utils.make_url(self.args.domain, self.args.uri) self.logger.debug('Sending {}?{}'.format(url, params_str)) path = self.args.uri + '?' + params_str headers.insert(0, (':path', path)) headers.extend([ ('content-length', str(len(body))), ]) # Start request with headers stream_id = await self.client.start_request( headers, end_stream=not body) # Send my name "world" as whole request body if body: await self.client.send_data(stream_id, body, end_stream=True) # Receive response headers headers = await self.client.recv_response(stream_id) self.logger.debug('Response headers: {}'.format(headers)) # Read all response body resp = await self.client.read_stream(stream_id, -1) dnsr = dns.message.from_wire(resp) dnsr.id = qid self.on_answer(addr, dnsr.to_wire()) # Read response trailers trailers = await self.client.recv_trailers(stream_id) self.logger.debug('Response trailers: {}'.format(trailers))
def test_make_url(self, domain, uri, output): self.assertEqual(utils.make_url(domain, uri), output)