forked from warecrer/Bettercap-caplets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy-script-test.js
45 lines (43 loc) · 1.6 KB
/
proxy-script-test.js
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
40
41
42
43
44
45
// called when script is loaded
function onLoad() {
console.log( "PROXY SCRIPT LOADED" );
}
// called before a request is proxied
function onRequest(req, res) {
if( req.Path == "/test-page" ){
for (var i = 0; i < res.Headers.length; i++) {
res.RemoveHeader(res.Headers[i].Name);
}
res.SetHeader("Server", "bettercap");
res.SetHeader("Connection", "close");
res.Status = 200;
res.ContentType = "text/html";
res.Body = "<html>" +
"<head>" +
"<title>Test Page</title>" +
"</head>" +
"<body>" +
"<div align=\"center\">Hello world from bettercap!</div>" +
"</body>" +
"</html>";
}
}
// called after a request is proxied and there's a response
function onResponse(req, res) {
if( res.Status == 404 ){
for (var i = 0; i < res.Headers.length; i++) {
res.RemoveHeader(res.Headers[i].Name);
}
res.SetHeader("Server", "bettercap");
res.SetHeader("Connection", "close");
res.ContentType = "text/html";
res.Body = "<html>" +
"<head>" +
"<title>Test 404 Page</title>" +
"</head>" +
"<body>" +
"<div align=\"center\">Custom 404 from bettercap.</div>" +
"</body>" +
"</html>";
}
}