def to_starlette_response(bolt_resp: BoltResponse) -> Response: resp = Response( status_code=bolt_resp.status, content=bolt_resp.body, headers=bolt_resp.first_headers_without_set_cookie(), ) for cookie in bolt_resp.cookies(): for name, c in cookie.items(): resp.set_cookie( key=name, value=c.value, max_age=c.get("max-age"), expires=c.get("expires"), path=c.get("path"), domain=c.get("domain"), secure=True, httponly=True, ) return resp
def to_sanic_response(bolt_resp: BoltResponse) -> HTTPResponse: resp = HTTPResponse( status=bolt_resp.status, body=bolt_resp.body, headers=bolt_resp.first_headers_without_set_cookie(), ) for cookie in bolt_resp.cookies(): for name, c in cookie.items(): resp.cookies[name] = c.value expire_value = c.get("expires") if expire_value is not None and expire_value != "": expire = datetime.strptime(expire_value, "%a, %d %b %Y %H:%M:%S %Z") resp.cookies[name]["expires"] = expire resp.cookies[name]["path"] = c.get("path") resp.cookies[name]["domain"] = c.get("domain") resp.cookies[name]["max-age"] = c.get("max-age") resp.cookies[name]["secure"] = True resp.cookies[name]["httponly"] = True return resp
def _write_response(self, bolt_resp: BoltResponse, resp: Response): resp.body = bolt_resp.body resp.status = str(bolt_resp.status) resp.set_headers(bolt_resp.first_headers_without_set_cookie()) for cookie in bolt_resp.cookies(): for name, c in cookie.items(): expire_value = c.get("expires", None) expire = (datetime.strptime(expire_value, "%a, %d %b %Y %H:%M:%S %Z") if expire_value else None) resp.set_cookie( name=name, value=c.value, expires=expire, max_age=c.get("max-age", None), domain=c.get("domain", None), path=c.get("path", None), secure=True, http_only=True, )