This repository has been archived by the owner on Nov 1, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed for latest version of Node and updated example.
- Loading branch information
Showing
4 changed files
with
70 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,26 @@ | ||
var proxy = require('./lib/proxy-tamper'); | ||
var proxy = require('./lib/proxy-tamper').start({port: 8080}); | ||
|
||
proxy.start({ port: 8080 }, function (p) { | ||
p.tamper(/\/test/, 'tampered'); | ||
// block all URLs that contain 'block' in them | ||
proxy.tamper(/block/, 'This content is blocked!'); | ||
|
||
p.tamper(/translate\.google\..*?\/translate_a\/t/, function (request) { | ||
// disallow translations | ||
request.url = request.url.replace(/hl=../, 'hl=en').replace(/tl=../, 'tl=en') | ||
.replace(/sl=../, 'sl=en').replace(/text=.*/, 'text=No+translation+for+you!'); | ||
}); | ||
// disallow Google | ||
proxy.tamper(/google/, function (request) { | ||
request.url = request.url.replace(/google/g, 'bing'); | ||
}); | ||
|
||
p.tamper(/tsyd\.net\/$/, function (request) { | ||
request.onResponse(function (response) { | ||
// called when we have the response from the tampered url | ||
|
||
response.body = reverseHeadings(response.body); | ||
response.headers['server'] = 'proxy-tamper 1337'; | ||
|
||
// the onResponse handler must complete the response | ||
response.complete(); | ||
}); | ||
}); | ||
}); | ||
// replace all instances of 'Apple' with 'Orange' in Techcrunch articles | ||
proxy.tamper(/techcrunch.com.*\/$/, function (request) { | ||
console.log('tampering ' + request.url); | ||
|
||
function reverseHeadings (str) { | ||
var matches = str.match(/(<h\d>.*?<\/h\d>)/mg); | ||
// gzip encoding is not supported when tampering the body | ||
delete request.headers['accept-encoding']; | ||
|
||
if (matches) { | ||
// reverse the text within all header tags | ||
matches.forEach(function (match) { | ||
var parts = match.match(/(<h\d>)(.*?)(<\/h\d>)/); | ||
str = str.replace(parts[0], | ||
parts[1] + parts[2].split('').reverse().join('') + parts[3]); | ||
}); | ||
} | ||
request.onResponse(function (response) { | ||
// tamper the body | ||
response.body = response.body.replace(/Apple/g, 'Orange'); | ||
response.headers['server'] = 'proxy-tamper 1337'; | ||
|
||
return str; | ||
}; | ||
// complete the response | ||
response.complete(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters