blob: 43f7d679fbcb453b47c58a283a45dc1652f955c8 (
plain)
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
33
34
35
36
37
38
39
|
import json
from cookies.resources import helpers
from wptserve.utils import isomorphic_decode
def main(request, response):
headers = helpers.setNoCacheAndCORSHeaders(request, response)
cookies = helpers.readCookies(request)
headers.append((b"Content-Type", b"text/html; charset=utf-8"))
tmpl = u"""
<!DOCTYPE html>
<script>
var data = %s;
data.type = "COOKIES";
try {
data.domcookies = document.cookie;
} catch (e) {}
if (window.parent != window) {
window.parent.postMessage(data, "*");
if (window.top != window.parent)
window.top.postMessage(data, "*");
}
if (window.opener)
window.opener.postMessage(data, "*");
window.addEventListener("message", e => {
console.log(e);
if (e.data == "reload")
window.location.reload();
});
</script>
"""
decoded_cookies = {isomorphic_decode(key): isomorphic_decode(val) for key, val in cookies.items()}
return headers, tmpl % json.dumps(decoded_cookies)
|