def cors_tool():
 req_head = cherrypy.request.headers
 resp_head = cherrypy.response.headers
 resp_head['Access-Control-Allow-Origin'] = req_head.get('Origin', '*')
 resp_head['Access-Control-Expose-Headers'] = 'GET, POST'
 resp_head['Access-Control-Allow-Credentials'] = 'true'
 if (cherrypy.request.method == 'OPTIONS'):
  cherrypy.serving.request.handler = cors_handler

def cors_tool ( ) : req_head = cherrypy . request . headers resp_head = cherrypy . response . headers resp_head [ 'Access-Control-Allow-Origin' ] = req_head . get ( 'Origin' , '*' ) resp_head [ 'Access-Control-Expose-Headers' ] = 'GET, POST' resp_head [ 'Access-Control-Allow-Credentials' ] = 'true' if ( cherrypy . request . method == 'OPTIONS' ) : cherrypy . serving . request . handler = cors_handler
handle both simple and complex cors requests add cors headers to each response .