Commit 674a3376 authored by Alexandre's avatar Alexandre
Browse files

[DoH] streams: Perform asynchronous requests

parent 4a3ed08a
......@@ -475,18 +475,18 @@ class ConnectionDoH(Connection):
self.prepare_get(request)
self.curl.handle.setopt(pycurl.NOBODY, True)
def perform(self):
self.buffer = io.BytesIO()
self.curl.handle.setopt(pycurl.WRITEDATA, self.buffer)
def perform(self, request):
request.buffer = io.BytesIO()
self.curl.handle.setopt(pycurl.WRITEDATA, request.buffer)
self.curl.handle.perform()
def send(self, request):
request.to_wire()
self.prepare(request)
self.perform()
self.perform(request)
def receive(self, request):
body = self.buffer.getvalue()
body = request.buffer.getvalue()
body_size = len(body)
http_code = self.curl.handle.getinfo(pycurl.RESPONSE_CODE)
content_type = self.curl.handle.getinfo(pycurl.CONTENT_TYPE)
......@@ -494,7 +494,7 @@ class ConnectionDoH(Connection):
request.response_size = body_size
request.rcode = http_code
request.ctype = content_type
self.buffer.close()
request.buffer.close()
def send_and_receive(self, request):
self.send(request)
......@@ -507,6 +507,8 @@ class ConnectionDoH(Connection):
if synchronous:
self.send_and_receive(request)
request.check_response()
else:
self.send(request)
return request
......@@ -565,7 +567,6 @@ def print_result(connection, request):
def read_results(connection, pending_requests):
for i in range(0, len(pending_requests)):
request = pending_requests[i]
connection.send(request)
connection.receive(request)
request.check_response()
return pending_requests
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment