refactor(main) generateHeaders

This commit is contained in:
coderaiser 2014-03-02 08:12:23 -05:00
parent eee94df771
commit d0b1e2dd71

View file

@ -197,37 +197,40 @@
* query
* https://developers.google.com/speed/docs/best-practices/caching?hl=ru#LeverageProxyCaching
*/
function generateHeaders(pParams) {
var lRet = Util.checkObjTrue(pParams, ['name']);
function generateHeaders(params) {
var header, p, extension, type, encoding, isContain, cmp;
if (lRet) {
var p = pParams,
lExt = Util.getExtension(p.name),
lType = ext[lExt] || 'text/plain',
lContentEncoding = '';
if (params.name) {
p = params,
extension = Util.getExtension(p.name),
type = ext[extension] || 'text/plain',
encoding = '';
/* if type of file any, but img - then we shoud specify charset */
if (!Util.isContainStr(lType, 'img'))
lContentEncoding = '; charset=UTF-8';
isContain = Util.isContainStr(type, ['img', 'image']);
if (!isContain)
encoding = '; charset=UTF-8';
if (Util.isContainStr(p.query, 'download'))
lType = 'application/octet-stream';
isContain = Util.isContainStr(p.query, 'download');
if (isContain)
type = 'application/octet-stream';
lRet = {
header = {
'Access-Control-Allow-Origin' : '*',
'Content-Type' : lType + lContentEncoding,
'last-modified' : new Date().toString(),
'Content-Type' : type + encoding,
'last-modified' : '' + new Date(),
'Vary' : 'Accept-Encoding'
};
if (!Util.strCmp(lExt, '.appcache') && p.cache)
lRet['cache-control'] = 'max-age=' + 31337 * 21;
cmp = Util.strCmp(ext, '.appcache');
if (!cmp && p.cache)
header['cache-control'] = 'max-age=' + 31337 * 21;
if (p.gzip)
lRet['content-encoding'] = 'gzip';
header['content-encoding'] = 'gzip';
}
return lRet;
return header;
}
function mainSetHeader(pParams) {