Save experiments
This commit is contained in:
parent
2e2496cd4c
commit
7254172545
7 changed files with 121 additions and 0 deletions
29
experiments/proxy.js
Normal file
29
experiments/proxy.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
var proxy = require('http-proxy').createProxyServer({
|
||||
target: {host: 'localhost', port: 9000}
|
||||
});
|
||||
var server = require('http').createServer(function(req, res) {
|
||||
console.log('[REQUEST] ' + req.url);
|
||||
if (req.method == 'POST') {
|
||||
var body = '';
|
||||
req.on('data', function (data) {
|
||||
body += data;
|
||||
});
|
||||
req.on('end', function () {
|
||||
print_body('[REQUEST.BODY] ', body);
|
||||
});
|
||||
}
|
||||
var _write = res.write;
|
||||
res.write = function(data) {
|
||||
print_body('[RESPONSE.BODY] ', data);
|
||||
_write.call(res, data);
|
||||
}
|
||||
proxy.web(req, res);
|
||||
});
|
||||
function print_body(header, body) {
|
||||
var text = String(body);
|
||||
console.log(header + text);
|
||||
for (var i = 0; i < text.length; i++) {
|
||||
console.log('body[%s] = %s = %s', i, text[i], text.charCodeAt(i));
|
||||
}
|
||||
}
|
||||
server.listen(8000);
|
||||
Loading…
Add table
Add a link
Reference in a new issue