At the end of the pipeline sits the application itself. AppHandler is a terminal handler: it produces the real response and never delegates, so it is always the last link in the chain.
Implement AppHandler.handle(request):
With this in place you can build the first real chain: auth.set_next(app). An authenticated request flows through auth into app and gets a 200; a request with no user is stopped at auth with a 401 and never reaches app.
class Handler:
def __init__(self):
self._next = None
def set_next(self, handler):
self._next = handler
return handler
def handle(self, request):
if self._next is not None:
return self._next.handle(request)
return None
class AuthHandler(Handler):
def handle(self, request):
if request.get("user") is None:
return {"status": 401, "body": "unauthorized"}
return super().handle(request)
class AppHandler(Handler):
def handle(self, request):
"""Terminal handler: build the 200 response and ignore any next handler."""
# TODO: return {"status": 200, "body": "ok:" + request["path"]}
pass
The editor and the test runner need a wide screen. Open this page on a desktop browser and your progress will be waiting.
At the end of the pipeline sits the application itself. AppHandler is a terminal handler: it produces the real response and never delegates, so it is always the last link in the chain.
Implement AppHandler.handle(request):
With this in place you can build the first real chain: auth.set_next(app). An authenticated request flows through auth into app and gets a 200; a request with no user is stopped at auth with a 401 and never reaches app.
Press Run Tests or ββ© to check your solution.