Created
September 11, 2014 07:04
-
-
Save ivoscc/2346fc05bc156551afca to your computer and use it in GitHub Desktop.
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
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