def set_cors_headers(req, resp, context, options):
try:<EOL><INDENT>request_context = context.request[id(req)]<EOL><DEDENT>except AttributeError:<EOL><INDENT>LOG.debug("<STR_LIT>")<EOL>return resp<EOL><DEDENT>evaluated = request_context.get(SANIC_CORS_EVALUATED, False)<EOL>if evaluated:<EOL><INDENT>LOG.debug('<STR_LIT>')<EOL>return resp<EOL><DEDENT>if resp is None:<EOL><INDENT>return None<EOL><DEDENT>if resp.headers is None:<EOL><INDENT>resp.headers = CIMultiDict()<EOL><DEDENT>headers_to_set = get_cors_headers(options, req.headers, req.method)<EOL>LOG.debug('<STR_LIT>', str(headers_to_set))<EOL>try:<EOL><INDENT>resp.headers.extend(headers_to_set)<EOL><DEDENT>except Exception as e1:<EOL><INDENT>for k, v in headers_to_set.items():<EOL><INDENT>try:<EOL><INDENT>resp.headers.add(k, v)<EOL><DEDENT>except Exception as e2:<EOL><INDENT>resp.headers[k] = v<EOL><DEDENT><DEDENT>return resp<EOL><DEDENT>
Performs the actual evaluation of Sanic-CORS options and actually
modifies the response object.

This function is used both in the decorator and the after_request
callback
:param sanic.request.Request req: