mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
feature(main) add Content-Length
This commit is contained in:
parent
a7a6d2e857
commit
34f6aa72a3
1 changed files with 30 additions and 17 deletions
|
|
@ -208,6 +208,9 @@
|
|||
|
||||
if(p.gzip)
|
||||
lRet['content-encoding'] = 'gzip';
|
||||
|
||||
if (!Util.isUndefined(p.length))
|
||||
lRet['Content-Length'] = p.length;
|
||||
}
|
||||
|
||||
return lRet;
|
||||
|
|
@ -226,24 +229,34 @@
|
|||
var p = pParams,
|
||||
lGzip = isGZIP(p.request) && p.gzip;
|
||||
|
||||
p.response.writeHead(OK, generateHeaders({
|
||||
name : p.name,
|
||||
cache : p.cache,
|
||||
gzip : lGzip,
|
||||
query : getQuery(p.request)
|
||||
}) );
|
||||
|
||||
stream.createPipe({
|
||||
from: p.name,
|
||||
write: p.response,
|
||||
zip : lGzip && !p.gziped,
|
||||
callback: function(pError) {
|
||||
var lError = pError && pError.toString();
|
||||
if (pError) {
|
||||
p.response.writeHead(FILE_NOT_FOUND, 'OK');
|
||||
p.response.end(lError);
|
||||
fs.stat(p.name, function(error, stat) {
|
||||
var length;
|
||||
|
||||
if (error)
|
||||
Util.log(error);
|
||||
else
|
||||
length = stat.size;
|
||||
|
||||
p.response.writeHead(OK, generateHeaders({
|
||||
name : p.name,
|
||||
cache : p.cache,
|
||||
gzip : lGzip,
|
||||
query : getQuery(p.request),
|
||||
length : length
|
||||
}) );
|
||||
|
||||
stream.createPipe({
|
||||
from: p.name,
|
||||
write: p.response,
|
||||
zip : lGzip && !p.gziped,
|
||||
callback: function(pError) {
|
||||
var lError = pError && pError.toString();
|
||||
if (pError) {
|
||||
p.response.writeHead(FILE_NOT_FOUND, 'OK');
|
||||
p.response.end(lError);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue