MCPcopy Create free account
hub / github.com/totaljs/framework / extend_response

Function extend_response

index.js:17360–18520  ·  view source on GitHub ↗
(PROTO)

Source from the content-addressed store, hash-verified

17358}
17359
17360function extend_response(PROTO) {
17361
17362 PROTORES = PROTO;
17363
17364 /**
17365 * Add a cookie into the response
17366 * @param {String} name
17367 * @param {Object} value
17368 * @param {Date/String} expires
17369 * @param {Object} options Additional options.
17370 * @return {Response}
17371 */
17372 PROTO.cookie = function(name, value, expires, options) {
17373
17374 var self = this;
17375
17376 if (self.headersSent || self.success)
17377 return;
17378
17379 var cookiename = name + '=';
17380 var builder = [cookiename + value];
17381 var type = typeof(expires);
17382
17383 if (expires && !U.isDate(expires) && type === 'object') {
17384 options = expires;
17385 expires = options.expires || options.expire || null;
17386 }
17387
17388 if (type === 'string')
17389 expires = expires.parseDateExpiration();
17390
17391 if (!options)
17392 options = {};
17393
17394 options.path = options.path || '/';
17395 expires && builder.push('Expires=' + expires.toUTCString());
17396 options.domain && builder.push('Domain=' + options.domain);
17397 options.path && builder.push('Path=' + options.path);
17398 options.secure && builder.push('Secure');
17399
17400 if (options.httpOnly || options.httponly || options.HttpOnly)
17401 builder.push('HttpOnly');
17402
17403 var same = options.security || options.samesite || options.sameSite;
17404 if (same) {
17405 switch (same) {
17406 case 1:
17407 same = 'lax';
17408 break;
17409 case 2:
17410 same = 'strict';
17411 break;
17412 }
17413 builder.push('SameSite=' + same);
17414 }
17415
17416 var arr = self.getHeader('set-cookie') || [];
17417

Callers 1

index.jsFile · 0.85

Calls 11

isGZIPFunction · 0.85
response_endFunction · 0.85
createTemporaryKeyFunction · 0.85
$file_notmodifiedFunction · 0.85
compile_checkFunction · 0.85
$file_rangeFunction · 0.85
fsStreamReadFunction · 0.85
$image_nocacheFunction · 0.85
fsFileExistsFunction · 0.85
prepare_errorFunction · 0.85
$decodeURIComponentFunction · 0.70

Tested by

no test coverage detected