Merge branch 'f0ckdev' into 'master'

fixed conns

See merge request !108
This commit is contained in:
Flummi 2017-05-25 18:02:44 +00:00
commit 19c2d224b1

View File

@ -178,31 +178,30 @@ function Websrv(tlib) {
|| contentType === "video/quicktime" || contentType === "video/quicktime"
|| contentType === "audio/mpeg" || contentType === "audio/mpeg"
|| contentType === "audio/ogg") && req.headers['range']) { || contentType === "audio/ogg") && req.headers['range']) {
var start = 0; fs.readFile(filePath, "binary", function(err, file) {
var end = 0; if(typeof req.headers.range !== 'undefined') {
var range = req.headers['range']; var range = req.headers.range;
fs.stat(filePath, (err, stat) => { var parts = range.replace(/bytes=/, "").split("-");
if(!err) { var partialstart = parts[0];
if(range != null) { var partialend = parts[1];
start = parseInt(range.slice(range.indexOf('bytes=')+6, range.indexOf('-'))); var total = file.length;
end = parseInt(range.slice(range.indexOf('-')+1, range.length)); var start = parseInt(partialstart, 10);
} var end = partialend ? parseInt(partialend, 10) : total-1;
if(isNaN(end) || end == 0) end = stat.size-1;
if(start > end) return;
res.writeHead(206, { res.writeHead(206, {
'Connection':'close', "Content-Range": "bytes " + start + "-" + end + "/" + (total),
'Content-Type':contentType, "Accept-Ranges": "bytes",
'Content-Length':end - start, "Content-Length": (end-start)+1,
'Content-Range':'bytes '+start+'-'+end+'/'+stat.size, "Transfer-Encoding": "chunked",
'Transfer-Encoding':'chunked' "Connection": "close"
}); });
var stream = fs.createReadStream(filePath, { flags: 'r', start: start, end: end}); res.write(file.slice(start, end)+'0', "binary");
stream.pipe(res);
} }
else { else {
res.writeHead(404); res.writeHead(200);
res.end('404 - f0ck you', 'utf-8'); res.write(file, "binary");
} }
res.end();
}); });
} }
else { else {