예제 #1
0
def set_response_headers(resp: falcon.Response, ct: str="application/ld+json", headers: Dict[str, Any]={}, status_code = falcon.HTTP_200) -> falcon.Response:
    resp.status = status_code
    resp.set_headers(headers)
    resp.set_header('Content-type', ct)
    resp.set_header('Link' ,'<' + get_hydrus_server_url(resp) + \
        get_api_name(resp)+'/vocab>; rel="http://www.w3.org/ns/hydra/core#apiDocumentation"')
    return resp
예제 #2
0
 def generate_response(res: Response,
                       status_code: int,
                       body_dict: dict,
                       headers: List[Dict] = []) -> NoReturn:
     res.status = get_http_status(status_code=status_code)
     res.media = body_dict
     res.set_headers(headers=headers)
예제 #3
0
def json_error_serializer(req: falcon.Request, resp: falcon.Response,
                          exception: BaseApiException):
    # Serialize exception
    resp.body = exception.to_json()

    # Set content type
    resp.content_type = "application/json"
    resp.append_header("Vary", "Accept")
    resp.status = exception.status

    # Setup CORS
    origin = req.headers.get("HTTP_ORIGIN")
    origin2 = req.headers.get("ORIGIN")
    origin = origin2 or origin
    headers = {}

    if settings.get("AWOKADO_DEBUG") or (origin
                                         and origin in settings.ORIGIN_HOSTS):
        headers["Access-Control-Allow-Origin"] = origin

    headers_to_set = settings.get("AWOKADO_ACCESS_CONTROL_HEADERS",
                                  DEFAULT_ACCESS_CONTROL_HEADERS)
    for k, v in headers_to_set:
        headers[k] = v

    resp.set_headers(headers)
예제 #4
0
def patch_response(resp: falcon.Response, headers, body, status):
    if body:
        resp.body = body
    resp.set_headers(headers)
    if isinstance(status, int):
        status = getattr(falcon, 'HTTP_{}'.format(status))
    resp.status = status
    return resp
예제 #5
0
def patch_response(resp: falcon.Response, headers, body, status):
    if body:
        resp.body = body
    resp.set_headers(headers)
    if isinstance(status, int):
        status = getattr(falcon, 'HTTP_{}'.format(status))
    resp.status = status
    return resp
예제 #6
0
 def create_response(data,
                     status_code=200,
                     headers=None,
                     content_type="application/json"):
     options = ResponseOptions()
     resp = Response(options)
     resp.body = data
     resp.content_type = content_type
     resp.status = HTTP_200
     resp.set_headers(headers or {})
     return resp
예제 #7
0
 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,
             )
예제 #8
0
 def process_response(self, req: Request, res: Response,
                      resource: BaseResource,
                      req_succeeded: bool) -> NoReturn:
     res.set_headers(
         headers={"request-track-id": RequestTrack.get_request_track_id()})
     RequestTrack.clear_request_track_id()
 def process_response(self, req: Request, res: Response,
                      resource: BaseResource,
                      req_succeeded: bool) -> NoReturn:
     res.set_headers(
         headers={"request-track-id": RequestTrack.request_track_id})
     self.__clear_tracking_ids()