Commit e57f8413 authored by Yury's avatar Yury

allow disable ssl

allow POST request
parent 3a430b44
Pipeline #72 passed with stages
in 10 minutes
......@@ -3,7 +3,7 @@ from .protocol import Protocol
class Connection:
def __init__(self, dispatcher_cls, loop, cert_path, key_path, prefix='dns-request', host='0.0.0.0', port=443):
def __init__(self, dispatcher_cls, loop, cert_path, key_path, prefix='dns-request', host='0.0.0.0', port=443, with_ssl=True):
self.dispatcher_cls = dispatcher_cls
self.loop = loop
self.cert_path = cert_path
......@@ -11,6 +11,7 @@ class Connection:
self.prefix = prefix
self.host = host
self.port = port
self.with_ssl = with_ssl
async def start(self):
print('Starting DNS-over-HTTPS server')
......
from aiohttp import web
import ssl
import base64
import json
class Protocol:
def __init__(self, connector):
self.connector = connector
self.app = web.Application(loop=self.connector.loop)
self.app.add_routes([web.get(f'/{connector.prefix}', self.handle)])
# self.ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
# self.ssl_context.load_cert_chain(connector.cert_path, connector.key_path)
if connector.with_ssl:
self.ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
self.ssl_context.load_cert_chain(connector.cert_path, connector.key_path)
async def handle(self, request):
dispatcher = self.connector.dispatcher_cls(loop=self.connector.loop)
......@@ -19,8 +20,12 @@ class Protocol:
result = await dispatcher.handle(decoded_query)
return web.Response(text=base64.b64encode(result).decode('ascii'))
elif request.method == 'POST':
pass
return web.Response(text='1234')
data = await request.json(loads=json.loads)
query = data['dns']
decoded_query = base64.b64decode(query + '=' * (4 - len(query) % 4))
result = await dispatcher.handle(decoded_query)
return web.Response(text=base64.b64encode(result).decode('ascii'))
return web.Response(text='')
async def start(self):
await web._run_app(self.app, port=self.connector.port, host=self.connector.host)
Markdown is supported
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