瀏覽代碼

Refactor auth/path handling in preparation for GET stream

master
JustAnotherArchivist 2 年之前
父節點
當前提交
a21b87dd00
共有 1 個檔案被更改,包括 8 行新增4 行删除
  1. +8
    -4
      http2irc.py

+ 8
- 4
http2irc.py 查看文件

@@ -804,7 +804,7 @@ class WebServer:
self._app = aiohttp.web.Application()
self._app.add_routes([
aiohttp.web.get('/status', self.get_status),
aiohttp.web.post('/{path:.+}', self.post)
aiohttp.web.post('/{path:.+}', functools.partial(self._path_request, func = self.post)),
])

self.update_config(config)
@@ -833,18 +833,22 @@ class WebServer:
self.logger.info(f'Received request {id(request)} from {request.remote!r} for {request.path!r}')
return (aiohttp.web.Response if (self.ircClient.lastRecvTime or 0) > time.time() - 600 else aiohttp.web.HTTPInternalServerError)()

async def post(self, request):
self.logger.info(f'Received request {id(request)} from {request.remote!r} for {request.path!r} with body {(await request.read())!r}')
async def _path_request(self, request, func):
self.logger.info(f'Received request {id(request)} from {request.remote!r} for {request.method} {request.path!r} with body {(await request.read())!r}')
try:
channel, auth, module, moduleargs, overlongmode = self._paths[request.path]
pathConfig = self._paths[request.path]
except KeyError:
self.logger.info(f'Bad request {id(request)}: no path {request.path!r}')
raise aiohttp.web.HTTPNotFound()
auth = pathConfig[1]
if auth:
authHeader = request.headers.get('Authorization')
if not authHeader or authHeader != auth:
self.logger.info(f'Bad request {id(request)}: authentication failed: {authHeader!r} != {auth}')
raise aiohttp.web.HTTPForbidden()
return (await func(request, *pathConfig))

async def post(self, request, channel, auth, module, moduleargs, overlongmode):
if module is not None:
self.logger.debug(f'Processing request {id(request)} using {module!r}')
try:


Loading…
取消
儲存