Skip to content

Instantly share code, notes, and snippets.

@val314159
Created September 23, 2014 03:39
Show Gist options
  • Save val314159/d448af5cc4111bc5de2d to your computer and use it in GitHub Desktop.
Save val314159/d448af5cc4111bc5de2d to your computer and use it in GitHub Desktop.
'''
small util lib for cors handling (in bottle)
'''
def add_headers(response):
'''
call this to slap the proper CORS headers into any dict-like object
'''
#allow_methods = ', '.join(['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'OPTIONS'])
allow_methods = ', '.join(['GET', 'HEAD', 'POST', 'OPTIONS'])
allow_headers = ', '.join(['Origin', 'X-Requested-With', 'Content-Type',
'Accept', 'Authorization', 'Access-Token'])
response.headers['Access-Control-Allow-Credentials'] = 'true';
#response.headers['Access-Control-Allow-Origin']='http://url:8080'
response.headers['Access-Control-Allow-Origin' ] = '*'
response.headers['Access-Control-Allow-Methods' ] = allow_methods
response.headers['Access-Control-Allow-Headers' ] = allow_headers
return ['OK']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment