-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathcors.py
More file actions
91 lines (83 loc) · 3.03 KB
/
Copy pathcors.py
File metadata and controls
91 lines (83 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# coding: utf-8
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from . import utils
class CORSMiddleware(object):
ALLOW_ORIGIN = utils.to_native("*")
ALLOW_HEADERS = utils.to_native(
", ".join(
[
"Content-Type",
"X-AVOSCloud-Application-Id",
"X-AVOSCloud-Application-Key",
"X-AVOSCloud-Application-Production",
"X-AVOSCloud-Client-Version",
"X-AVOSCloud-Request-sign",
"X-AVOSCloud-Session-Token",
"X-AVOSCloud-Super-Key",
"X-Requested-With",
"X-Uluru-Application-Id," "X-Uluru-Application-Key",
"X-Uluru-Application-Production",
"X-Uluru-Client-Version",
"X-Uluru-Session-Token",
"X-LC-Hook-Key",
"X-LC-Id",
"X-LC-Key",
"X-LC-Prod",
"X-LC-Session",
"X-LC-Sign",
"X-LC-UA",
]
)
)
ALLOW_METHODS = utils.to_native(
", ".join(["PUT", "GET", "POST", "DELETE", "OPTIONS"])
)
MAX_AGE = utils.to_native("86400")
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
if environ["REQUEST_METHOD"] == "OPTIONS":
start_response(
utils.to_native("200 OK"),
[
(
utils.to_native("Access-Control-Allow-Origin"),
environ.get("HTTP_ORIGIN", self.ALLOW_ORIGIN),
),
(
utils.to_native("Access-Control-Allow-Headers"),
self.ALLOW_HEADERS,
),
(
utils.to_native("Access-Control-Allow-Methods"),
self.ALLOW_METHODS,
),
(utils.to_native("Access-Control-Max-Age"), self.MAX_AGE),
],
)
return [utils.to_native("")]
else:
def cors_start_response(status, headers, exc_info=None):
headers.append(
(utils.to_native("Access-Control-Allow-Origin"), self.ALLOW_ORIGIN)
)
headers.append(
(
utils.to_native("Access-Control-Allow-Headers"),
self.ALLOW_HEADERS,
)
)
headers.append(
(
utils.to_native("Access-Control-Allow-Methods"),
self.ALLOW_METHODS,
)
)
headers.append(
(utils.to_native("Access-Control-Max-Age"), self.MAX_AGE)
)
return start_response(status, headers, exc_info)
return self.app(environ, cors_start_response)