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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/mixed-content/generic/expect.py

Issue 2697453005: Import wpt@758b3b4cfa805067f36121333ba031e583d3a62c (Closed)
Patch Set: Add -expected.txt files. Created 3 years, 10 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 import json, os, urllib, urlparse
2
3 def redirect(url, response):
4 response.add_required_headers = False
5 response.writer.write_status(301)
6 response.writer.write_header("access-control-allow-origin", "*")
7 response.writer.write_header("location", url)
8 response.writer.end_headers()
9 response.writer.write("")
10
11 def create_redirect_url(request, swap_scheme = False):
12 parsed = urlparse.urlsplit(request.url)
13 destination_netloc = parsed.netloc
14 scheme = parsed.scheme
15
16 if swap_scheme:
17 scheme = "http" if parsed.scheme == "https" else "https"
18 hostname = parsed.netloc.split(':')[0]
19 port = request.server.config["ports"][scheme][0]
20 destination_netloc = ":".join([hostname, str(port)])
21
22 # Remove "redirection" from query to avoid redirect loops.
23 parsed_query = dict(urlparse.parse_qsl(parsed.query))
24 assert "redirection" in parsed_query
25 del parsed_query["redirection"]
26
27 destination_url = urlparse.urlunsplit(urlparse.SplitResult(
28 scheme = scheme,
29 netloc = destination_netloc,
30 path = parsed.path,
31 query = urllib.urlencode(parsed_query),
32 fragment = None))
33
34 return destination_url
35
36 def main(request, response):
37 if "redirection" in request.GET:
38 redirection = request.GET["redirection"]
39 if redirection == "no-redirect":
40 pass
41 elif redirection == "keep-scheme-redirect":
42 redirect(create_redirect_url(request, swap_scheme=False), response)
43 return
44 elif redirection == "swap-scheme-redirect":
45 redirect(create_redirect_url(request, swap_scheme=True), response)
46 return
47 else:
48 raise ValueError ("Invalid redirect type: %s" % redirection)
49
50 content_type = "text/plain"
51 response_data = ""
52
53 if "action" in request.GET:
54 action = request.GET["action"]
55
56 if "content_type" in request.GET:
57 content_type = request.GET["content_type"]
58
59 key = request.GET["key"]
60 stash = request.server.stash
61 path = request.GET.get("path", request.url.split('?'))[0]
62
63 if action == "put":
64 value = request.GET["value"]
65 stash.take(key=key, path=path)
66 stash.put(key=key, value=value, path=path)
67 response_data = json.dumps({"status": "success", "result": key})
68 elif action == "purge":
69 value = stash.take(key=key, path=path)
70 if content_type == "image/png":
71 response_data = open(os.path.join(request.doc_root,
72 "images",
73 "smiley.png"), "rb").read()
74 elif content_type == "audio/mpeg":
75 response_data = open(os.path.join(request.doc_root,
76 "media",
77 "sound_5.oga"), "rb").read()
78 elif content_type == "video/mp4":
79 response_data = open(os.path.join(request.doc_root,
80 "media",
81 "movie_5.mp4"), "rb").read()
82 elif content_type == "application/javascript":
83 response_data = open(os.path.join(request.doc_root,
84 "mixed-content",
85 "generic",
86 "worker.js"), "rb").read()
87 else:
88 response_data = "/* purged */"
89 elif action == "take":
90 value = stash.take(key=key, path=path)
91 if value is None:
92 status = "allowed"
93 else:
94 status = "blocked"
95 response_data = json.dumps({"status": status, "result": value})
96
97 response.add_required_headers = False
98 response.writer.write_status(200)
99 response.writer.write_header("content-type", content_type)
100 response.writer.write_header("cache-control", "no-cache; must-revalidate")
101 response.writer.end_headers()
102 response.writer.write(response_data)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698