Skip to content

Instantly share code, notes, and snippets.

@ivoscc
Created September 11, 2014 07:04
Show Gist options
  • Save ivoscc/2346fc05bc156551afca to your computer and use it in GitHub Desktop.
Save ivoscc/2346fc05bc156551afca to your computer and use it in GitHub Desktop.
var http = require("http");
var server = http.createServer(function (req, res) {
// needs to be a big enough file for the download not to finish inmediately
var url = "http://lolpics.se/pics/1871.jpg";
res.writeHead(200, {"Content-Type": "application/octet- stream",
"Content-Disposition": "attachment; filename='big.jpg'"});
var file_request = http.request(url, function(file_response) {
file_response.pipe(res);
file_response.on("data", function(data) {
// watch it flow!
console.log(data);
});
}).on("error", function(e) {
console.log(e.toString());
res.end("Nope");
});
file_request.end();
});
server.listen(8000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment