Good Day Sirs.
i have an issue while using node js to just proxy a GET request
through node JS and it hangs giving the following issue

Error 4
{ [Error: socket hang up] code: 'ECONNRESET' }

i have tried different methods but still the same
all that the code does is just remove the range request forcing
youtube videoplayback to fall back to the old request i;e; getting
full file not 1.7M ranges from it with a hope that squid-cahe would
cache it


much regards for the help in advance

hereby is the code i am using

#!/usr/bin/node
/*
        AdyWeb NodeJs 2012
        Faysal Banna
        degre...@gmail.com
*/

/*
        Require Module Variables
*/

var http=require('http');
var url=require('url');
var util=require('util');
var path=require('path');
var qs=require('querystring');

/*
        Set Max Agent open sockets for http requests
*/
http.Agent.maxSockets=10000;



var AdyRequestHandler = function(req,res){

        /*
                Request Handler a function that handles the requests
        */
        /*
                get req handles and attributes
        */

        var myheaders={};
        myheaders['host']=req['headers']['host'];
        myheaders['port']=80;
        myheaders['method']=req['method'];
        /*if(req['headers'].hasOwnProperty('range') === true){
                delete req['headers']['range'];
        }*/
        myheaders['headers']=req['headers'];
        myheaders['agent']=false;
        /*
                chop the url and get its parts from req.url
        */
        var URL=url.parse(req.url);
        /*
                chop the parsed url and get the query attribute
        */
        var QUERY=qs.parse(URL['query']);
        /*
                MovieID is the id tag movie taken from the query itself
        */
        var MovieID=QUERY['id'];
        /*
                resolution itag is the itag taken from the query itself
        */
        var MovieTag=QUERY['itag'];

        if (QUERY.hasOwnProperty('range') === true ){
                /*
                        We delete the range in the querystring so we get it as 
one chunk
and not chopped
                */
                delete QUERY['range'];
        }
        if (QUERY.hasOwnProperty('begin') === true ) {
                delete QUERY['range'];
        }
        /*
                assign FinalQuery to hold the query to be sent to root servers
                and thus range query request option is deleted thus we get one 
whole
big file instead
                in the reply
        */
        var FinalQuery=qs.stringify(QUERY);
        /*
                myheaders['path'] to hold the new path that should be requested 
for
fetching and delivery
                with its query part having the range option removed
        */
        myheaders['path']=URL['pathname']+'?'+FinalQuery;
        //      console.log(myheaders['path']);
        /*
                Open a head Request to get the details about our file to be
downloaded
        */
        /*
                open a http.get request with its options as myheaders populated
above
        */
        var FwReq = http.get(myheaders,function(FwRes){
                res.writeHead(302,FwRes['headers']);
                FwRes.on('data',function(chunk){
                        res.write(chunk);
                });
                FwRes.on('end',function(){
                        res.end();
                });
        });
        FwReq.on('error',function(err){
                console.log('Error 4');
                console.log(err);
        });
        req.on('close',function(){
                FwReq.abort();
        });
}

/*
        initiate the server
*/
var Server=http.createServer(AdyRequestHandler);
Server.listen(6910);

/*-------------------------------------------------------*/

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to