def handler(self, request: Request, response: Response, *args, **kwargs): handler = getattr(self, request.method.lower(), None) if handler is None: response.status = 401 response.content_type = 'application/json' response.body = '{"code": 401, "message": "method not allowed"}' return response return handler(request, response, *args, **kwargs)
def handle(self, req: Request, resp: Response) -> str: if req.method == "GET": if self.app.oauth_flow is not None: oauth_flow: OAuthFlow = self.app.oauth_flow if req.path == oauth_flow.install_path: bolt_resp = oauth_flow.handle_installation(to_bolt_request(req)) set_response(bolt_resp, resp) return bolt_resp.body or "" elif req.path == oauth_flow.redirect_uri_path: bolt_resp = oauth_flow.handle_callback(to_bolt_request(req)) set_response(bolt_resp, resp) return bolt_resp.body or "" elif req.method == "POST": bolt_resp: BoltResponse = self.app.dispatch(to_bolt_request(req)) set_response(bolt_resp, resp) return bolt_resp.body or "" resp.status = 404 return "Not Found"
def set_response(bolt_resp: BoltResponse, resp: Response) -> None: resp.status = bolt_resp.status for k, values in bolt_resp.headers.items(): for v in values: resp.add_header(k, v)