8fe0bbc by Anon Ray at 2014-05-10 |
1 |
# HTTP utilities |
|
2 |
from flask import current_app |
d120774 by Anon Ray at 2014-03-08 |
3 |
|
8fe0bbc by Anon Ray at 2014-05-10 |
4 |
def makeCORSHeaders(response, host_url): |
|
5 |
current_app.logger.debug('makeCORSHeaders(): client\'s host_url: %s', |
|
6 |
host_url) |
f867edb by Anon Ray at 2014-04-10 |
7 |
response.headers['Access-Control-Allow-Origin'] = host_url |
|
8 |
response.headers['Access-Control-Max-Age'] = '3600' |
|
9 |
response.headers['Access-Control-Allow-Credentials'] = 'true' |
|
10 |
response.headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept' |
|
11 |
|
8fe0bbc by Anon Ray at 2014-05-10 |
12 |
current_app.logger.debug('Updated headers %s', response.headers) |
d120774 by Anon Ray at 2014-03-08 |
13 |
|
|
14 |
return response |
8fe0bbc by Anon Ray at 2014-05-10 |
15 |
|
|
16 |
from datetime import timedelta |
|
17 |
from flask import make_response, request, current_app |
|
18 |
from functools import update_wrapper |
|
19 |
|
|
20 |
""" |
|
21 |
def crossdomain(origin=None, methods=None, headers=None, max_age=3600, |
|
22 |
attach_to_all=True, automatic_options=True): |
|
23 |
|
|
24 |
if methods is not None: |
|
25 |
methods = ', '.join(sorted(i.upper() for i in methods)) |
|
26 |
if headers in not None and not isinstance(headers, basestring): |
|
27 |
headers = ', '.join(i.upper() for i in headers) |
|
28 |
if not isinstance(origin, basestring): |
|
29 |
origin = ', '.join(origin) |
|
30 |
if isinstance(max_age, timedelta): |
|
31 |
max_age = max_age.total_seconds() |
|
32 |
|
|
33 |
def get_methods(): |
|
34 |
if methods is not None: |
|
35 |
return methods |
|
36 |
|
|
37 |
options_resp = current |
|
38 |
|
|
39 |
""" |