Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(540)

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/fetch/api/resources/preflight.py

Issue 2778753002: Import //fetch from Web Platform Tests. (Closed)
Patch Set: Baselines. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 def main(request, response):
2 headers = [("Content-Type", "text/plain")]
3 stashed_data = {'control_request_headers': "", 'preflight': "0", 'preflight_ referrer': ""}
4
5 token = None
6 if "token" in request.GET:
7 token = request.GET.first("token")
8
9 if "origin" in request.GET:
10 for origin in request.GET['origin'].split(", "):
11 headers.append(("Access-Control-Allow-Origin", origin))
12 else:
13 headers.append(("Access-Control-Allow-Origin", "*"))
14
15 if "credentials" in request.GET:
16 headers.append(("Access-Control-Allow-Credentials", "true"))
17
18 if request.method == "OPTIONS":
19 if not "Access-Control-Request-Method" in request.headers:
20 response.set_error(400, "No Access-Control-Request-Method header")
21 return "ERROR: No access-control-request-method in preflight!"
22
23 if "control_request_headers" in request.GET:
24 stashed_data['control_request_headers'] = request.headers.get("Acces s-Control-Request-Headers", None)
25
26 if "max_age" in request.GET:
27 headers.append(("Access-Control-Max-Age", request.GET['max_age']))
28
29 if "allow_headers" in request.GET:
30 headers.append(("Access-Control-Allow-Headers", request.GET['allow_h eaders']))
31
32 if "allow_methods" in request.GET:
33 headers.append(("Access-Control-Allow-Methods", request.GET['allow_m ethods']))
34
35 preflight_status = 200
36 if "preflight_status" in request.GET:
37 preflight_status = int(request.GET.first("preflight_status"))
38
39 stashed_data['preflight'] = "1"
40 stashed_data['preflight_referrer'] = request.headers.get("Referer", "")
41 if token:
42 request.server.stash.put(token, stashed_data)
43
44 return preflight_status, headers, ""
45
46
47 if token:
48 data = request.server.stash.take(token)
49 if data:
50 stashed_data = data
51
52 #use x-* headers for returning value to bodyless responses
53 headers.append(("Access-Control-Expose-Headers", "x-did-preflight, x-control -request-headers, x-referrer, x-preflight-referrer, x-origin"))
54 headers.append(("x-did-preflight", stashed_data['preflight']))
55 if stashed_data['control_request_headers'] != None:
56 headers.append(("x-control-request-headers", stashed_data['control_request _headers']))
57 headers.append(("x-preflight-referrer", stashed_data['preflight_referrer']))
58 headers.append(("x-referrer", request.headers.get("Referer", "") ))
59 headers.append(("x-origin", request.headers.get("Origin", "") ))
60
61 if token:
62 request.server.stash.put(token, stashed_data)
63
64 return headers, ""
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698