Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dominictarr
Forked from fjakobs/index.html
Created July 29, 2011 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dominictarr/1113432 to your computer and use it in GitHub Desktop.
Save dominictarr/1113432 to your computer and use it in GitHub Desktop.
node-http-proxy bug #70
var http = require('http')
function log (str) {
console.log('' + str)
}
http.get({host: 'localhost', port:6666, path: '/xhr'}, function (res) {
res.on('data', log)
res.on('end', log)
console.log('response', res)
})
<html>
<body>
JUHU
<script>
var req = new XMLHttpRequest();
req.multipart = true;
req.open("GET", "/xhr");
req.onload = function(){
if (req.readyState == 4)
console.log("load:" + req.responseText);
};
req.send();
</script>
</body>
</html>
var index = require("fs").readFileSync(__dirname + "/index.html");
require("http").createServer(function(req, res) {
if (req.url == "/xhr") {
console.log("xhr")
var headers = {};
headers['Content-Type'] = 'multipart/x-mixed-replace;boundary="socketio"';
headers['Connection'] = 'keep-alive';
// headers['Connection'] = 'close';
res.useChunkedEncodingByDefault = false;
res.shouldKeepAlive = true;
res.writeHead(200, headers);
res.write("--socketio\n");
var count = 10;
function write() {
if (count-- == 0) {
console.log("close")
res.end();
return;
}
var message = Date.now() + " " + count;
console.log("write", message);
res.write("Content-Type: text/plain\n\n");
res.write(message + "\n");
res.write("--socketio\n");
setTimeout(write, 500);
}
write();
}
else {
res.writeHead(200, {"Content-Type": "text/html"});
res.end(index);
}
}).listen(/*process.env.C9_PORT || */6666);
var httpProxy = require('http-proxy');
//httpProxy.createServer(6666, 'localhost').listen(6060);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment