def cors_handler(*args, **kwargs):
    '''
    Check a CORS preflight request and return a valid response
    '''
    req_head = cherrypy.request.headers
    resp_head = cherrypy.response.headers

    ac_method = req_head.get('Access-Control-Request-Method', None)

    allowed_methods = ['GET', 'POST']
    allowed_headers = ['X-Auth-Token', 'Content-Type']

    if ac_method and ac_method in allowed_methods:
        resp_head['Access-Control-Allow-Methods'] = ', '.join(allowed_methods)
        resp_head['Access-Control-Allow-Headers'] = ', '.join(allowed_headers)

        resp_head['Connection'] = 'keep-alive'
        resp_head['Access-Control-Max-Age'] = '1400'

    return {}
dataset/ETHPy150Open saltstack/salt/salt/netapi/rest_cherrypy/app.py/cors_handler/original