diff --git a/lib/server/main.js b/lib/server/main.js index aed18a2f..47e8bf0a 100644 --- a/lib/server/main.js +++ b/lib/server/main.js @@ -11,7 +11,7 @@ SLASH, ISWIN32, ext, - path, fs, zlib, url, pipe, CloudFunc, diffPatch, querystring, + path, fs, zlib, url, pipe, CloudFunc, diffPatch, querystring, time, OK, FILE_NOT_FOUND, MOVED_PERMANENTLY, REQUEST, RESPONSE, @@ -114,7 +114,7 @@ exports.hash = srvrequire('hash'), diffPatch = librequire('diff/diff-match-patch').diff_match_patch, exports.diff = new (librequire('diff').DiffProto)(diffPatch), - exports.time = srvrequire('time'); + exports.time = time = srvrequire('time'); exports.users = srvrequire('users'); exports.rest = srvrequire('rest').api, exports.update = srvrequire('update'), @@ -218,10 +218,13 @@ header = { 'Access-Control-Allow-Origin' : '*', 'Content-Type' : type + encoding, - //'Last-Modified' : '' + new Date(), 'Vary' : 'Accept-Encoding' }; + if (p.time) { + header['Last-Modified'] = p.time; + } + cmp = Util.strCmp(ext, '.appcache'); if (!cmp && p.cache) header['Cache-Control'] = 'max-age=' + 31337 * 21; @@ -239,10 +242,11 @@ if (lRet) { p = pParams; - lGzip = isGZIP(p.request) && p.gzip; + lGzip = p.isGzip || isGZIP(p.request) && p.gzip; header = generateHeaders({ name : p.name, + time : p.time, cache : p.cache, gzip : lGzip, query : getQuery(p.request) @@ -261,22 +265,37 @@ * @param pGzip - данные сжаты gzip'ом */ function sendFile(params) { - var isGzip, - p = params, - ret = checkParams(params); + var isGzip, getTime, + p = params, + ret = checkParams(params); if (ret) { isGzip = isGZIP(p.request) && p.gzip; - mainSetHeader(params); + getTime = Util.bind(time.get, p.name, { + str: true + }); - pipe.create({ - from : p.name, - write : p.response, - gzip : isGzip, - callback: function(error) { - if (error) - sendError(params, error); + getTime(function(error, time) { + if (error) { + sendError(params, error); + } else { + Util.copyObj(p, { + isGzip : isGzip, + time : time + }); + + mainSetHeader(params); + + pipe.create({ + from : p.name, + write : p.response, + gzip : isGzip, + callback: function(error) { + if (error) + sendError(params, error); + } + }); } }); }