Merge branch 'f0ckdev' into 'master'
fixed conns See merge request !108
This commit is contained in:
commit
19c2d224b1
|
@ -178,32 +178,31 @@ 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, {
|
"Content-Range": "bytes " + start + "-" + end + "/" + (total),
|
||||||
'Connection':'close',
|
"Accept-Ranges": "bytes",
|
||||||
'Content-Type':contentType,
|
"Content-Length": (end-start)+1,
|
||||||
'Content-Length':end - start,
|
"Transfer-Encoding": "chunked",
|
||||||
'Content-Range':'bytes '+start+'-'+end+'/'+stat.size,
|
"Connection": "close"
|
||||||
'Transfer-Encoding':'chunked'
|
});
|
||||||
});
|
res.write(file.slice(start, end)+'0', "binary");
|
||||||
var stream = fs.createReadStream(filePath, { flags: 'r', start: start, end: end});
|
}
|
||||||
stream.pipe(res);
|
else {
|
||||||
}
|
res.writeHead(200);
|
||||||
else {
|
res.write(file, "binary");
|
||||||
res.writeHead(404);
|
}
|
||||||
res.end('404 - f0ck you', 'utf-8');
|
res.end();
|
||||||
}
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fs.readFile(filePath, (error, content) => {
|
fs.readFile(filePath, (error, content) => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user