-
Notifications
You must be signed in to change notification settings - Fork 25
/
proxy.html
36 lines (35 loc) · 1.28 KB
/
proxy.html
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
<html>
<head>
<meta charset="UTF-8">
<meta name="referrer" content="origin">
<title>Proxy</title>
</head>
<body>
<script>
window.addEventListener('message', function(event) {
var data = event.data;
var source = event.source;
if (data && data.message === 'proxyMessage' && data.message_id && data.method && data.url) {
var xhr = new XMLHttpRequest();
xhr.timeout = data.timeout || 60 * 1000;
xhr.withCredentials = !!data.withCredentials;
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE) {
source.postMessage({
message: 'proxyResponse',
message_id: data.message_id,
status: xhr.status,
responseText: xhr.responseText
}, '*');
}
};
xhr.open(data.method, data.url);
if (data.method === 'POST') {
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
}
xhr.send(data.post_data);
}
});
</script>
</body>
</html>