MCPcopy Index your code
hub / github.com/restify/node-restify / patch

Function patch

lib/response.js:41–847  ·  view source on GitHub ↗

* Patch Response object and extends with extra functionalities * * @private * @function patch * @param {http.ServerResponse|http2.Http2ServerResponse} Response - * Server Response * @returns {undefined} No return value

(Response)

Source from the content-addressed store, hash-verified

39 * @returns {undefined} No return value
40 */
41function patch(Response) {
42 assert.func(Response, 'Response');
43
44 /**
45 * Wraps all of the node
46 * [http.ServerResponse](https://nodejs.org/docs/latest/api/http.html)
47 * APIs, events and properties, plus the following.
48 * @class Response
49 * @extends http.ServerResponse
50 */
51
52 /**
53 * Sets the `cache-control` header.
54 *
55 * @public
56 * @memberof Response
57 * @instance
58 * @function cache
59 * @param {String} [type="public"] - value of the header
60 * (`"public"` or `"private"`)
61 * @param {Object} [options] - an options object
62 * @param {Number} options.maxAge - max-age in seconds
63 * @returns {String} the value set to the header
64 */
65 Response.prototype.cache = function cache(type, options) {
66 if (typeof type !== 'string') {
67 options = type;
68 type = 'public';
69 }
70
71 if (options && options.maxAge !== undefined) {
72 assert.number(options.maxAge, 'options.maxAge');
73 type += ', max-age=' + options.maxAge;
74 }
75
76 return this.setHeader('Cache-Control', type);
77 };
78
79 /**
80 * Turns off all cache related headers.
81 *
82 * @public
83 * @memberof Response
84 * @instance
85 * @function noCache
86 * @returns {Response} self, the response object
87 */
88 Response.prototype.noCache = function noCache() {
89 // HTTP 1.1
90 this.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
91
92 // HTTP 1.0
93 this.setHeader('Pragma', 'no-cache');
94
95 // Proxies
96 this.setHeader('Expires', '0');
97
98 return this;

Callers

nothing calls this directly

Calls 2

flushFunction · 0.85
formatterErrorFunction · 0.85

Tested by

no test coverage detected