OLD | NEW |
(Empty) | |
| 1 def main(request, response): |
| 2 token = request.GET.first("token", None) |
| 3 if "querystate" in request.GET: |
| 4 from json import JSONEncoder |
| 5 response.headers.set("Content-Type", "text/plain") |
| 6 return JSONEncoder().encode(request.server.stash.take(token)) |
| 7 content = request.GET.first("content", None) |
| 8 tag = request.GET.first("tag", None) |
| 9 date = request.GET.first("date", None) |
| 10 expires = request.GET.first("expires", None) |
| 11 vary = request.GET.first("vary", None) |
| 12 cc = request.GET.first("cache_control", None) |
| 13 redirect = request.GET.first("redirect", None) |
| 14 inm = request.headers.get("If-None-Match", None) |
| 15 ims = request.headers.get("If-Modified-Since", None) |
| 16 pragma = request.headers.get("Pragma", None) |
| 17 cache_control = request.headers.get("Cache-Control", None) |
| 18 ignore = "ignore" in request.GET |
| 19 |
| 20 if tag: |
| 21 tag = '"%s"' % tag |
| 22 |
| 23 server_state = request.server.stash.take(token) |
| 24 if not server_state: |
| 25 server_state = [] |
| 26 state = dict() |
| 27 if not ignore: |
| 28 if inm: |
| 29 state["If-None-Match"] = inm |
| 30 if ims: |
| 31 state["If-Modified-Since"] = ims |
| 32 if pragma: |
| 33 state["Pragma"] = pragma |
| 34 if cache_control: |
| 35 state["Cache-Control"] = cache_control |
| 36 server_state.append(state) |
| 37 request.server.stash.put(token, server_state) |
| 38 |
| 39 if tag: |
| 40 response.headers.set("ETag", '%s' % tag) |
| 41 elif date: |
| 42 response.headers.set("Last-Modified", date) |
| 43 if expires: |
| 44 response.headers.set("Expires", expires) |
| 45 if vary: |
| 46 response.headers.set("Vary", vary) |
| 47 if cc: |
| 48 response.headers.set("Cache-Control", cc) |
| 49 |
| 50 # The only-if-cached redirect tests wants CORS to be okay, the other tests |
| 51 # are all same-origin anyways and don't care. |
| 52 response.headers.set("Access-Control-Allow-Origin", "*"); |
| 53 |
| 54 if redirect: |
| 55 response.headers.set("Location", redirect); |
| 56 response.status = (302, "Redirect") |
| 57 return "" |
| 58 elif ((inm is not None and inm == tag) or |
| 59 (ims is not None and ims == date)): |
| 60 response.status = (304, "Not Modified") |
| 61 return "" |
| 62 else: |
| 63 response.status = (200, "OK") |
| 64 response.headers.set("Content-Type", "text/plain") |
| 65 return content |
OLD | NEW |