pluto-http-client
Version:
HTTP client for NodeJS. Inspired in the Java JAX-RS spec so you can expect excellence, versatility and extensibility.
172 lines (171 loc) • 4.83 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Cookie = exports.SameSite = void 0;
const http_header_reader_1 = require("../utils/http-header-reader");
var SameSite;
(function (SameSite) {
SameSite["NONE"] = "None";
SameSite["LAX"] = "Lax";
SameSite["STRICT"] = "Strict";
})(SameSite = exports.SameSite || (exports.SameSite = {}));
class Cookie {
constructor(name, value, version, path, domain, comment, maxAge, expiry, secure, httpOnly, sameSite) {
this._name = name;
this._value = value || "";
this._version = version || 1;
this._path = path;
this._domain = domain;
this._comment = comment;
this._maxAge = maxAge;
this._expiry = expiry;
this._secure = secure;
this._httpOnly = httpOnly;
this._sameSite = sameSite;
}
id() {
return this.name;
}
clone() {
return new Cookie(this.name, this.value, this.version, this.path, this.domain, this.comment, this.maxAge, this.expiry, this.secure, this.httpOnly, this.sameSite);
}
equals(other) {
if (!other) {
return false;
}
else if (!(other instanceof Cookie)) {
return false;
}
else {
if (this.name !== other.name) {
return false;
}
else if (this.value !== other.value) {
return false;
}
else if (this.version !== other.version) {
return false;
}
else if (this.path !== other.path) {
return false;
}
else if (this.domain !== other.domain) {
return false;
}
else if (this.comment !== other.comment) {
return false;
}
else if (this.maxAge != other.maxAge) {
return false;
}
else if (this.expiry !== other.expiry) {
return false;
}
else if (this.secure !== other.secure) {
return false;
}
else if (this.httpOnly !== other.httpOnly) {
return false;
}
else {
return this.sameSite === other.sameSite;
}
}
}
get name() {
return this._name;
}
get value() {
return this._value;
}
get version() {
return this._version;
}
set version(value) {
this._version = value;
}
get path() {
return this._path;
}
set path(value) {
this._path = value;
}
get domain() {
return this._domain;
}
set domain(value) {
this._domain = value;
}
get comment() {
return this._comment;
}
set comment(value) {
this._comment = value;
}
get maxAge() {
return this._maxAge;
}
set maxAge(value) {
this._maxAge = value;
}
get expiry() {
return this._expiry;
}
set expiry(value) {
this._expiry = value;
}
get secure() {
return this._secure;
}
set secure(value) {
this._secure = value;
}
get httpOnly() {
return this._httpOnly;
}
set httpOnly(value) {
this._httpOnly = value;
}
get sameSite() {
return this._sameSite;
}
set sameSite(value) {
this._sameSite = value;
}
static fromString(header) {
return http_header_reader_1.HttpHeaderReader.parseCookie(header);
}
toString() {
const buffer = [`${this.name}`, "="];
http_header_reader_1.HttpHeaderReader.appendQuotedIfWhitespace(buffer, this.value);
buffer.push(`;Version=${this.version}`);
if (this.comment) {
buffer.push(";Comment=");
http_header_reader_1.HttpHeaderReader.appendQuotedIfWhitespace(buffer, this.comment);
}
if (this.domain) {
buffer.push(";Domain=");
http_header_reader_1.HttpHeaderReader.appendQuotedIfWhitespace(buffer, this.domain);
}
if (this.path) {
buffer.push(";Path=");
http_header_reader_1.HttpHeaderReader.appendQuotedIfWhitespace(buffer, this.path);
}
if (this.maxAge && this.maxAge != -1) {
buffer.push(`;MaxAge=${this.maxAge}`);
}
if (this.secure) {
buffer.push(";Secure");
}
if (this.httpOnly) {
buffer.push(";HttpOnly");
}
if (this.expiry) {
buffer.push(`;Expires=${this.expiry.toDateString()}`);
}
if (this.sameSite) {
buffer.push(`;SameSite=${this.sameSite}`);
}
return buffer.join("");
}
}
exports.Cookie = Cookie;