node-web-mvc
Version:
node spring mvc
43 lines (42 loc) • 1.61 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @module ResourceCacheControl
* @description 静态资源缓存配置
*/
const CacheControl_1 = __importDefault(require("../http/CacheControl"));
const HttpHeaders_1 = __importDefault(require("../http/HttpHeaders"));
class ResourceCacheControl {
constructor(request, response, cacheControl) {
this.request = request;
this.response = response;
this.cacheControl = cacheControl;
if (cacheControl) {
this.applyCacheControl();
}
else {
this.cacheControl = new CacheControl_1.default({});
this.applyCacheControl();
}
}
applyCacheControl() {
const response = this.response;
const ccValue = this.cacheControl.toString();
if (ccValue) {
// Set computed HTTP 1.1 Cache-Control header
response.setHeader(HttpHeaders_1.default.CACHE_CONTROL, ccValue);
if (response.containsHeader(HttpHeaders_1.default.PRAGMA)) {
// Reset HTTP 1.0 Pragma header if present
response.setHeader(HttpHeaders_1.default.PRAGMA, '');
}
if (response.containsHeader(HttpHeaders_1.default.EXPIRES)) {
// Reset HTTP 1.0 Expires header if present
response.setHeader(HttpHeaders_1.default.EXPIRES, '');
}
}
}
}
exports.default = ResourceCacheControl;