UNPKG

pluto-http-client

Version:

HTTP client for NodeJS. Inspired in the Java JAX-RS spec so you can expect excellence, versatility and extensibility.

139 lines (138 loc) 3.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CacheControl = void 0; class CacheControl { constructor() { this._privateFields = []; this._noCacheFields = []; this._cacheExtension = new Map(); this._isPrivate = false; this._isNoCache = false; this._isNoStore = false; this._isNoTransform = false; this._isMustRevalidate = false; this._isProxyRevalidate = false; this._maxAge = -1; this._sMaxAge = -1; } get privateFields() { return this._privateFields; } set privateFields(value) { this._privateFields = value; } get noCacheFields() { return this._noCacheFields; } set noCacheFields(value) { this._noCacheFields = value; } get cacheExtension() { return this._cacheExtension; } set cacheExtension(value) { this._cacheExtension = value; } get isPrivate() { return this._isPrivate; } set isPrivate(value) { this._isPrivate = value; } get isNoCache() { return this._isNoCache; } set isNoCache(value) { this._isNoCache = value; } get isNoStore() { return this._isNoStore; } set isNoStore(value) { this._isNoStore = value; } get isNoTransform() { return this._isNoTransform; } set isNoTransform(value) { this._isNoTransform = value; } get isMustRevalidate() { return this._isMustRevalidate; } set isMustRevalidate(value) { this._isMustRevalidate = value; } get isProxyRevalidate() { return this._isProxyRevalidate; } set isProxyRevalidate(value) { this._isProxyRevalidate = value; } get maxAge() { return this._maxAge; } set maxAge(value) { this._maxAge = value; } get sMaxAge() { return this._sMaxAge; } set sMaxAge(value) { this._sMaxAge = value; } toString() { let buffer = new Array(); if (this.isPrivate) { CacheControl.appendQuotedWithSeperator(buffer, "private", CacheControl.buildListValue(this.privateFields)); } if (this._isNoCache) { CacheControl.appendQuotedWithSeperator(buffer, "no-cache", CacheControl.buildListValue(this.noCacheFields)); } if (this.isNoStore) { CacheControl.appendWithSeperator(buffer, "no-store"); } if (this.isNoTransform) { CacheControl.appendWithSeperator(buffer, "no-transform"); } if (this.isMustRevalidate) { CacheControl.appendWithSeperator(buffer, "must-revalidate"); } if (this.isProxyRevalidate) { CacheControl.appendWithSeperator(buffer, "proxy-revalidate"); } if (this.maxAge != -1) { CacheControl.appendWithSeperator(buffer, "max-age", this.maxAge.toString()); } if (this.sMaxAge != -1) { CacheControl .appendWithSeperator(buffer, "s-maxage", this.maxAge.toString()); } return buffer.join(""); } static buildListValue(values) { const buffer = new Array(); for (const value of values) { buffer.push(value); } return buffer.join(", "); } static appendWithSeperator(buffer, field, value) { if (buffer.length > 0) { buffer.push(", "); } buffer.push(field); if (value) { buffer.push(value); } } static appendQuotedWithSeperator(buffer, field, value) { CacheControl.appendWithSeperator(buffer, field); if (value != null && !(value.length === 0)) { buffer.push("=\""); buffer.push(value); buffer.push("\""); } } } exports.CacheControl = CacheControl;