diff options
| author | 2021-10-09 01:53:41 +0000 | |
|---|---|---|
| committer | 2021-10-09 01:53:41 +0000 | |
| commit | a21b87dd00cf11ab93faef641547412bfdcfed8e (patch) | |
| tree | 6c6a7147436fbce58e7e74708225234ae1c3a1f1 /http2irc.py | |
| parent | Merge changes from irclog (diff) | |
| signature | ||
Refactor auth/path handling in preparation for GET stream
Diffstat (limited to 'http2irc.py')
| -rw-r--r-- | http2irc.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/http2irc.py b/http2irc.py index c71e082..03f6ad7 100644 --- a/http2irc.py +++ b/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: |
