title: req.headers.range cant find if call from android devices?
body: <p>I try to make streaming of audio file in nodeJS. But If i call from browser than it still work good but if call from any devices than it's not work because of range not found.</p>
  
  <pre><code>//If call from Browser req.headers output like
  { host: 'localhost:7060',
    connection: 'keep-alive',
    'user-agent': 'stagefright/1.2 (Linux;Android 4.4.4)',
    'accept-encoding': 'gzip,deflate',
     range: 'bytes=1-696319' }
  
  //If call from devices
  { host: 'localhost',
   'user-agent': 'stagefright/1.1 (Linux;Android 2.3.6)' }
  </code></pre>
  
  <p>only that output occurs i can't found any ranges here what can i do for that?</p>
  
  <p>app.js file </p>
  
  <pre><code>var fs = require('fs'),
  queryString = require('querystring');
  
  var query, URI;
  
  exports.streamMP3 = function(req, res){
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "X-Requested-With");
  res.header("Access-Control-Allow-Credentials", "true");
  res.header("crossDomain","true");
  res.header("Range","bytes=1-999");
  //console.log(req);
  try{
      query = URI = null;
      //console.log("METHOD:", req.method);
      if(req.method=='POST') {
          query =  req.body;
      }else{
          URI = decodeURIComponent(req.url);
          if (req.url.indexOf('?') &gt;= 0) {
              query = queryString.parse(req.url.replace(/^.*\?/, ''));
          }
      }
      console.log("QUERY:", query);
  
      var audio_file_path = null;
      var audio_file_id = null;
      if(query &amp;&amp; query.id){
          audio_file_id = query.id;
          audio_file_path = './mp3/'+audio_file_id+'.mp3';
      }else{
          audio_file_path = './mp3/tmp.mp3';
      }
  
      fs.readFile(audio_file_path, "binary", function(err, file) {
  
          var header = {};
          // add content type to header
          //req.headers.range = 'bytes=1-696319';
  
          console.log(req.headers);
          //TODO: any more clean solution ?
          if(typeof req.headers.range != 'undefined'){
              // browser wants chunged transmission
              var range = req.headers.range;
              var parts = range.replace(/bytes=/, "").split("-");
              var partialstart = parts[0]; 
              var partialend = parts[1]; 
  
              var total = file.length; 
  
              var start = parseInt(partialstart,10); 
              var end = partialend ? parseInt(partialend,10) : total-1;
  
              var diff = end - start;
              var value = parseInt((partialend*20)/100,10);
              if(diff &gt; value){
                  end = start + value;
              }
              var chunksize = (end-start)-10000; 
  
              console.log(start , end);
              //var end = parseInt((partialend*20)/100, 10);
              header["Content-Range"] = "bytes " + start + "-" + end + "/" + (total);
              header["Accept-Ranges"] = "bytes";
              header["Content-Length"]= chunksize;
              header['Transfer-Encoding'] = 'chunked';
              header["Connection"] = "close";
              //console.log(start, end);
  
              res.writeHead(206, header); 
              // yeah I dont know why i have to append the '0'
              // but chrome wont work unless i do
              //res.end(file.slice(start, chunksize), "binary"); 
              res.write(file.slice(start, end)+'0', "binary");
          }else{
              console.log("Unchunked");
              // reply to normal un-chunked request
              res.writeHead(200, header );
              res.write(file, "binary");
          }
          res.end();
      });
  }catch(e){
      console.log("TRY ERROR:", e);
      res.end();
  }
  }
  </code></pre>