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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/fetch/http-cache/resources/http-cache.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 from json import JSONEncoder, JSONDecoder
2 from base64 import b64decode
3
4 def main(request, response):
5 uuid = request.GET.first("token", None)
6 if "querystate" in request.GET:
7 response.headers.set("Content-Type", "text/plain")
8 return JSONEncoder().encode(request.server.stash.take(uuid))
9
10 server_state = request.server.stash.take(uuid)
11 if not server_state:
12 server_state = []
13
14 requests = JSONDecoder().decode(b64decode(request.GET.first("info", "")))
15 config = requests[len(server_state)]
16
17 state = dict()
18 state["request_method"] = request.method
19 state["request_headers"] = dict([[h.lower(), request.headers[h]] for h in re quest.headers])
20 server_state.append(state)
21 request.server.stash.put(uuid, server_state)
22
23 note_headers = ['content-type', 'access-control-allow-origin', 'last-modifie d', 'etag']
24 noted_headers = {}
25 for header in config.get('response_headers', []):
26 if header[0].lower() in ["location", "content-location"]: # magic!
27 header[1] = "%s&target=%s" % (request.url, header[1])
28 response.headers.set(header[0], header[1])
29 if header[0].lower() in note_headers:
30 noted_headers[header[0].lower()] = header[1]
31
32 if "access-control-allow-origin" not in noted_headers:
33 response.headers.set("Access-Control-Allow-Origin", "*");
34 if "content-type" not in noted_headers:
35 response.headers.set("Content-Type", "text/plain")
36 response.headers.set("Server-Request-Count", len(server_state))
37
38 code, phrase = config.get("response_status", [200, "OK"])
39
40 if request.headers.get("If-Modified-Since", False) == noted_headers.get('las t-modified', True):
41 code, phrase = [304, "Not Modified"]
42 if request.headers.get("If-None-Match", False) == noted_headers.get('etag', True):
43 code, phrase = [304, "Not Modified"]
44
45 response.status = (code, phrase)
46
47 content = config.get("response_body", uuid)
48 if code in [204, 304]:
49 return ""
50 else:
51 return content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698