-
Notifications
You must be signed in to change notification settings - Fork 54
/
origin-policy
32 lines (22 loc) · 1017 Bytes
/
origin-policy
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
import os
import glob
def main(request, response):
host_piece = request.url_parts.hostname.split(".")[0]
# Default return code for manifests if found.
return_code = 200
# Reserve 'op99' for tests that should use return code 404.
if host_piece == "op99":
return_code = 404
# Default mime type for returned data.
content_type = "application/originpolicy+json"
# Reserve 'op100' for testing incorrect mime type for manifest file.
if host_piece == "op100":
content_type = "text/plain"
filepath_pattern = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(
__file__)), "../origin-policy/policies/", "{} *.json".format(host_piece)))
matches = glob.glob(filepath_pattern)
if len(matches) != 1:
return 404, [], '{} origin policies found at a path matching "{}"'.format(len(matches), filepath_pattern)
with open(matches[0]) as f:
data = f.read()
return return_code, [('Content-Type', content_type)], data