Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var server = http.createServer(function(req, res) {
- //1. Setting up a server, getting information for each request and listen to a port
- //Internal processing
- //Retrieving download piece of information
- //Retrieving client piece of information
- //declaring stream function
- var stream = function(data){
- var options = {
- url: data.url,
- pool: {maxSockets: Infinity},
- localAddress: data.bind,
- headers:{
- 'Cookie': data.parsed.cookie,
- 'User-Agent': data.parsed.agent,
- 'Connection': 'close'
- },
- timeout: 5000
- }
- try{
- //Streams
- var remote = request(options, function (error, response, body) {
- if(error) {
- console.log(error)
- }
- })
- var stream = req.pipe(remote).pipe(res)
- //Event handlers (on error/finish event)
- remote.on('error',function(){
- console.log([res],"Remote: error happened")
- });
- stream.on('error',function(){
- console.log([res,stream],"Stream: error happened")
- })
- stream.on('finish',function(){
- console.log([res,stream],"Stream: finished/ended")
- })
- } catch (error) {
- console.log([res],"Remote/Stream: "+error)
- }
- }
- //Parsing url and parameters
- //2. Getting remote info
- //Using exec to call a php file and get remote info
- //3. Serve the content
- stream({url: downloadInfos.u,bind: downloadInfos.bind, parsed: parsed},req,res)
- })
Add Comment
Please, Sign In to add comment